I am building an android app that saves a place ID retrieved from the PlaceAutocomplete API. At a later point, I am trying to get the details of the place using the getPlaceById() API. I see that the callback is never getting called.
I have set the following permission:
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
I have also added the API_KEY:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value=<API KEY>/>
However, I am unable to retrieve the place details. "onResult" never seems to be getting called. Can anyone please help me with where I might be going wrong?
Thanks!
Below is the code snippet that I am using. Have hardcoded the PlaceId here for simplicity :
PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi.getPlaceById(mGoogleApiClient, "ChIJi-t8KwUWrjsRlp-L9ykb2_k");
placeResult.setResultCallback(new ResultCallback<PlaceBuffer>() {
@Override
public void onResult(PlaceBuffer places) {
Log.i(TAG, "Testing");
if (places.getStatus().isSuccess() && places.getCount() > 0) {
final Place myPlace = places.get(0);
Log.i(TAG, "Place found: " + myPlace.getName());
} else {
Log.e(TAG, "Place not found");
}
places.release();
}
});
I just found out what I was missing out. I missed out the call to mGoogleApiClient.connect(); in the onStart() of the activity. Works like a charm now! :)
The comment in the onCreate() in the below link states that we need to call connect() and disconnect() explicitly if the activity does not extend FragmentActivity.