Reputation: 2712
I am searching for something where, I needs to pass my current location details(latitude and longitude) and retrieve the type of current place.
For example, If I am standing at ATM, and If I pass the latitude and longitude, Google should return me something like ATM as type.
For this purpose, I am using Google Places API
PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
.getCurrentPlace(mGoogleApiClient, null);
result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
@Override
public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
for (PlaceLikelihood placeLikelihood : likelyPlaces) {
Log.i(TAG, String.format("Place '%s' has likelihood: %g",
placeLikelihood.getPlace().getName(),
placeLikelihood.getLikelihood()));
}
likelyPlaces.release();
}
});
This is the main focus of code.
But Here It returns list of places Instead of one. I supposed that, Inside getCurrentPlace function of PlaceDetectionApi I should pass the radius instead of null. But I am not getting how to pass it. And my GoogleApiClient object is
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.enableAutoManage(this, this)
.build();
Thank you guys in advance.
Upvotes: 3
Views: 376
Reputation: 9009
Google should return me place type. visit getPlacesTypes()
List<Integer> types = placeLikelihood.getPlace().getPlaceTypes();
But Here It returns list of places Instead of one
That is obvious that same location can be related to other places also. Check @cricket_007 comment.
Upvotes: 1