Arel Sharon
Arel Sharon

Reputation: 27

Converting a PlaceID string to LatLng object

Im trying to convert a placeId String which I stored on a database to LatLng coordinates, I got the id like so: place.getId() from a place object and now when I retirived it from the server I would like to convert it back into coordinates or at least a Place object.

Thank you!

Upvotes: 1

Views: 258

Answers (1)

Marco
Marco

Reputation: 350

Declare the object as

GoogleApiClient mGoogleApiClient;

Then initialise it as

 mGoogleApiClient =
            new GoogleApiClient.Builder(...)
            ...
            .build();

And pass it to the Places API's function.

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

And retrieve the coordinates in the callback. (code copied from here)

Upvotes: 1

Related Questions