2012-06-27 54 views
0

我有下面的类型获取位置数组获取纬度,但它不能工作。 我的代码有错吗?我可以得到结果,但我无法得到几何。如何从谷歌地方API获取位置JSON(android)

JSONTokener jsonParser = new JSONTokener(strResult); 
JSONObject jsonObject = new JSONObject(strResult); 

JSONArray routeObject = jsonObject.getJSONArray("results"); 

routeObject.getJSONObject(0).getJSONArray("geometry").getJSONObject(0).getJSONArray("location").getJSONObject(0).getDouble("lat") 

回答

0

我做了这种方式:

谷歌地图网址:

http://maps.google.com/maps/geo?q=“+ fullAddress;

我读它:

JSONObject response = new JSONObject(result); 
JSONObject point = response.getJSONArray("Placemark").getJSONObject(0).getJSONObject("Point"); 

      lat = point.getJSONArray("coordinates").getString(1); 
      lng = point.getJSONArray("coordinates").getString(0); 

希望它帮助!

0

我从来没有使用google-places-api,但我只是尝试了一些东西。我只是从https://developers.google.com/maps/documentation/places/地方搜索响应示例文件,并将其复制到一个文件作为输入。 (编辑:我使用http://code.google.com/p/google-gson/解码)

我的代码来解码JsonFile看起来像,并为您的latitude你正在寻找:

 JsonParser parser = new JsonParser(); 
     JsonObject obj = (JsonObject)parser.parse(new FileReader(path)); 

     for(Entry<String, JsonElement> entry : obj.entrySet()) { 
      String key = entry.getKey(); 
      System.out.println(key); 

      if(key.trim().equals("results".trim())) { 
       for(JsonElement ele2 : entry.getValue().getAsJsonArray()) { 
        System.out.println(ele2.getAsJsonObject().get("geometry").getAsJsonObject().get("location").getAsJsonObject().get("lat")); 
       } 
      } 
     } 
相关问题