0

緯度を取得するために Location 配列を取得するために以下のように入力していますが、機能しません。私のコードに間違いはありますか?結果は取得できますが、ジオメトリを取得できません。

 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")
4

2 に答える 2

0

を使ったことはありませんgoogle-places-apiが、何か試してみました。https://developers.google.com/maps/documentation/places/place-search-response からサンプル ファイルを取得し、入力としてファイルにコピーしました(編集: 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"));
                }
            }
        }
于 2012-06-27T14:26:23.597 に答える
0

私はこのようにします:

Google マップの URL:

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);

それが役に立てば幸い!

于 2012-06-27T14:07:58.127 に答える