Php 如何从地理编码中获取区域名称列表
我从地理编码中得到了一个地区名称,我的代码是Php 如何从地理编码中获取区域名称列表,php,android,google-maps,Php,Android,Google Maps,我从地理编码中得到了一个地区名称,我的代码是 $geocode=file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng='.$latitude.','.$longitude.'&sensor=false'); 我可以在这里列出lat和long,而不是一个lat和long,因为我有700个点和地理编码,计算时间太长。我的朋友,这很容易。首先,请阅读您的url中的响应。。。它将返回json,然后
$geocode=file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng='.$latitude.','.$longitude.'&sensor=false');
我可以在这里列出lat和long,而不是一个lat和long,因为我有700个点和地理编码,计算时间太长。我的朋友,这很容易。首先,请阅读您的url中的响应。。。它将返回json,然后使用以下代码运行
public static String getAddress(JSONObject result) {
if (result.has("results")) {
try {
JSONArray array = result.getJSONArray("results");
if (array.length() > 0) {
JSONObject place = array.getJSONObject(0);
JSONArray components = place.getJSONArray("address_components");
for (int i = 0; i < components.length(); i++) {
JSONObject component = components.getJSONObject(i);
JSONArray types = component.getJSONArray("types");
for (int j = 0; j < types.length(); j++) {
if (types.getString(j).equals("route")) {
return component.getString("long_name");
}
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
return null;
}
在我当前的代码中,我正在为特定的路由解析它。。。。只需跳过条件并将结果保存在数据结构对象中,但我如何给出lat lng列表以获取地址数组,请告诉我或给我行。