1

ジオコーディングAPIの座標を取得する方法を教えてください。これは、geocoding api perimeterの時点でジオメトリを持つジオコーディングAPIのjsonresultを取得できるようになりました。:{ "bounds":{ "北東":{ "LAT":37.842911、 "LNG":-85.682537 }、 "南西":{ "LAT":37.559684、 "LNG":-86.07509399999999 }}、 " location:{ "lat":37.7030051、 "lng":-85.8647201 }、 "LOCATION_TYPE": "近似"、 は "ビューポート":{ "北東":{ "LAT":37.842911、 "LNG":-85.682537 }、 "南西":{ "LAT":37.559684、 「LNG」:-86.07509399999999 }} }、ジオコーディングで選択された領域の周辺を取得する方法api android?

マップのように、この周囲を達成するために使用するのに最適な一部である可能性がありますか?

答えて

4

メソッドは、Google Maps Android API Utility Libraryから利用できます。このメソッドはパラメータとしてList<LatLng>を受け取り、パスの長さを計算するので、リストには閉じたパスを含める必要があります。

あなたのJSONをデコードし、このように周囲を計算することができます。

try { 
    String jsonString = "{ \"bounds\" : { \"northeast\" : { \"lat\" : 37.842911, \"lng\" : -85.682537 }, \"southwest\" : { \"lat\" : 37.559684, \"lng\" : -86.07509399999999 } }, \"location\" : { \"lat\" : 37.7030051, \"lng\" : -85.8647201 }, \"location_type\" : \"APPROXIMATE\", \"viewport\" : { \"northeast\" : { \"lat\" : 37.842911, \"lng\" : -85.682537 }, \"southwest\" : { \"lat\" : 37.559684, \"lng\" : -86.07509399999999 } } }"; 
    JSONObject object = new JSONObject(jsonString); 

    JSONObject boundsJSON = object.getJSONObject("bounds"); 
    LatLng northeast = getLatLng(boundsJSON.getJSONObject("northeast")); 
    LatLng southwest = getLatLng(boundsJSON.getJSONObject("southwest")); 
    LatLng northwest = new LatLng(northeast.latitude, southwest.longitude); 
    LatLng southeast = new LatLng(southwest.latitude, northeast.longitude); 

    List<LatLng> path = new ArrayList<>(); 
    path.add(northwest); 
    path.add(northeast); 
    path.add(southeast); 
    path.add(southwest); 
    path.add(northwest); 
    double perimeter = SphericalUtil.computeLength(path); 
} catch (JSONException e) { 
    // TODO: Handle the exception 
    String a = ""; 
} 

これは、(上記のコードで使用される)座標をデコードgetLatLng方法であって、

private LatLng getLatLng(JSONObject coordinateJSON) throws JSONException { 
    double lat = coordinateJSON.getDouble("lat"); 
    double lon = coordinateJSON.getDouble("lng"); 

    return new LatLng(lat, lon); 
} 
+0

病気つもりはこれを試しますポストのためにありがとう –

関連する問題