2017-05-09 11 views
1

GoogleプレイスAPIを使用してカスタムプレイスピッカーを作成しようとしています。地図がスクロールされたときのGoogle Place Pickerコントロールでは、ピンの位置が変更され、新しいピンの位置に対応する近くの場所が取得されます。 iOS/Android Google Places APIでは、デバイスの現在地から近くの場所を取得するAPIしか表示されません。Google Places APIを使用して地図をスクロールすると周辺の場所を更新するにはどうすればよいですか?

緯度/経度の近くで近くの場所を取得するために使用できるGoogleプレイスWebService APIはありますが、iOS/Android APIを通じて可能ですか?

iOS/Android Google Places APIを使用してマップをスクロールした特定の座標の近くの場所を取得するにはどうすればよいですか?

答えて

-1

カスタムロケーションを選択するには、place pickerを使用する必要があります。

次のコードは、場所選択ツールを起動します。

int PLACE_PICKER_REQUEST = 1; 
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); 
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST); 
1

近くの場所のため、このPOSTメソッドを使用し

メートルであなたのSEARCH TYPEと半径を設定します。

String url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json" + "?location=" + location.getLatitude() + "," + location.getLongitude() + "&radius=" + RADIUS_IN_METERS + "&type=" + SEARCH_TYPE + "&key=" + API_KEY; 
Log.d(TAG, url); 
Map<String, String> params = new HashMap<>(); 
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, new JSONObject(params), 
    new Response.Listener<JSONObject>() {   
    @Override 
    public void onResponse(JSONObject response) { 
    try { 
      locationList = new ArrayList<>(); 
      JSONArray results = response.getJSONArray("results"); 
      for (int i = 0; i < results.length(); i++) { 
        JSONObject geometry = results.getJSONObject(i).getJSONObject("geometry"); 
        String name = results.getJSONObject(i).getString("name"); 
        String address = results.getJSONObject(i).getString("vicinity"); 
        String place_id = results.getJSONObject(i).getString("place_id"); 
        if (geometry != null) { 
          JSONObject location = geometry.getJSONObject("location"); 
          if (location != null) { 
            double latitude = location.getDouble("lat"); 
            double longitude = location.getDouble("lng"); 
            if (latitude != 0.0 && longitude != 0.0) { 
              Location markerLocation = new Location(SEARCH_TYPE); 
              markerLocation.setLatitude(latitude); 
              markerLocation.setLongitude(longitude); 
              Bundle bundle = new Bundle(); 
              bundle.putString("NAME", name); 
              bundle.putString("ADDRESS", address); 
              bundle.putString("PLACE_ID", place_id); 
              bundle.putString("TYPE", SEARCH_TYPE); 
              markerLocation.setExtras(bundle); 
              locationList.add(markerLocation); 
              Log.d(TAG, latitude + " " + longitude); 
             } 
            } 
           } 

          } 
          if (locationList.size() != 0) { 
           addMarkers(SEARCH_TYPE); 
          } 
          //Log.d(TAG,results.toString()); 
         } catch (JSONException e) { 
          e.printStackTrace(); 
         } 
        } 
       }, 
       new Response.ErrorListener() { 
        @Override 
        public void onErrorResponse(VolleyError error) { 

        } 
       } 
     ); 
    requestQueue.add(jsonObjectRequest); 
関連する問題