简体   繁体   中英

Google Places Api Android

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.

To get Atm List , Here is Google official link to get atm list of nearer location

Click on Place type Google will give you input parameter for place type, there you have to pass following parameter from the list . to know list of parameter click on this link

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM