get Lat Lang from a place_id returned by autocomplete place api get Lat Lang from a place_id returned by autocomplete place api android android

get Lat Lang from a place_id returned by autocomplete place api


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

Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId)    .setResultCallback(new ResultCallback<PlaceBuffer>() {  @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


Google Place Details is the answer.

From the place_id you got, query Place Details something like https://maps.googleapis.com/maps/api/place/details/json?placeid={placeid}&key={key} and you can get the lat and lng from result.geometry.location JSON.


do provide Place.Field.LAT_LNG to get the latitude and longitude for the place.

 autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID,  Place.Field.NAME,Place.Field.LAT_LNG));

then get LatLng

LatLng destinationLatLng = place.getLatLng();

and can see through toast

 destlat = destinationLatLng.latitude; destLon = destinationLatLng.longitude; Toast.makeText(getApplicationContext(), "" + destlat + ',' + destLon, Toast.LENGTH_LONG).show();