I am trying to get list of the nearby places using Google Places API. I have enabled requried API from Google Devloper Console and have an valid API key. I am able to get my corrent location. After I got the my current location I am trying to get nearby places list but it returns empty.
I have also tried giving null
PlaceFilter
but it gives same result.
private class MyGoogleMapOnMyLocationListener implements
OnMyLocationChangeListener,
ConnectionCallbacks,
OnConnectionFailedListener {
private GoogleApiClient mGoogleApiClient;
@Override
public void onMyLocationChange(Location location) {
if (!hasLastLocation) {
hasLastLocation = true;
mLastLocation = location;
Log.d(LOG_TAG, "Location: " + location.toString());
if (googleMap != null ) {
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(location.getLatitude(), location.getLongitude()), 16.0f));
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient
.Builder(getActivity())
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
}
}
}
}
@Override
public void onConnected(Bundle bundle) {
Log.d(LOG_TAG, "Google Api Client connected.");
if (mGoogleApiClient != null) {
Log.d(LOG_TAG, "Getting nearby places...");
PendingResult<PlaceLikelihoodBuffer> result =
Places.PlaceDetectionApi.getCurrentPlace(mGoogleApiClient, null);
result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
@Override
public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
Log.d(LOG_TAG, "Got results: " + likelyPlaces.getCount() + " place found.");
for (PlaceLikelihood placeLikelihood : likelyPlaces) {
Log.i(LOG_TAG, String.format("Place '%s' has likelihood: %g",
placeLikelihood.getPlace().getName(),
placeLikelihood.getLikelihood()));
}
likelyPlaces.release();
}
});
}
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
}
Here is my AndroidManifest.xml
Here is my map Fragment
I have followed indtructions from Google Places API for Android
And I have tried accepted answer of this question: Show Current Location and Nearby Places and Route between two places using Google Maps API in Android
UPDATE
I have enabled other map related APIs from Google Developer Console and it worked.