2014-10-01 61 views
0

Iam从我的代码地理编码中获取地区名称。如何从地理编码中获取地区名称列表

$geocode=file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng='.$latitude.','.$longitude.'&sensor=false'); 

我可以在这里给的纬度列表和长而不是一个纬度和长,因为我有一个700分,地理编码花费过多的时间来计算。

回答

0

这很容易我的朋友。首先阅读你的网址的回应。 ......它会回报你的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; 
} 

在我当前的代码,我解析它的具体途径....只是跳过条件和结果保存在您的数据结构对象

+0

但我如何给拉特lng列表获取地址数组可以请告诉我或给我的线。 – 2014-10-02 05:28:31

相关问题