get Lat Lang from a place_id returned by autocomplete place api

前端 未结 12 1438
情深已故
情深已故 2021-02-02 05:58

I am searching the place in my apps using the google autocomplete place api and now I want to get latitude and longitude of the place that i have searched. How to get latitude a

12条回答
  •  囚心锁ツ
    2021-02-02 06:16

    The following code snippet which uses Google Places API for android worked for me

    Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId)
        .setResultCallback(new ResultCallback() {
      @Override
      public void onResult(PlaceBuffer places) {
        if (places.getStatus().isSuccess()) {
          final Place myPlace = places.get(0);
          LatLng queriedLocation = myPlace.getLatLng();
          Log.v("Latitude is", "" + queriedLocation.latitude);
          Log.v("Longitude is", "" + queriedLocation.longitude);
        }
        places.release();
      }
    });
    

    Visit Google Places API for Android for a full list of methods to retrieve data from a place

提交回复
热议问题