Reputation: 159
I am using Google Places API for Android and am trying to limit the results to only show Restaurants. I have included a PlaceFilter and seems to be correct but doesn't seem to be applying the filter and giving other results aside from Restaurants. See code:
ArrayList<String> restrictToRestaurants = new ArrayList<>();
restrictToRestaurants.add(Integer.toString(Place.TYPE_RESTAURANT));
PlaceFilter pf;
pf = new PlaceFilter(false, restrictToRestaurants);
PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi.getCurrentPlace(mGoogleApiClient, pf);
result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
@Override
public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
for (PlaceLikelihood placeLikelihood : likelyPlaces) {
placeLikelihood.getPlace().getPlaceTypes();
Log.i(TAG, String.format("Place '%s' with " + "likelihood: %g", placeLikelihood.getPlace().getName(), placeLikelihood.getLikelihood()));
}
likelyPlaces.release();
}
});
Anyone have any ideas how to apply the PlaceFilter?
Upvotes: 1
Views: 2061
Reputation: 1691
Currently, the only ways to filter the results of getCurrentPlace
are outlined in the PlaceFilter class:
requireOpenNow if true, return only places open now
restrictToPlaceIds the specific PlaceIds to match
Each one of those PlaceIds is supposed to match to a specific location. Unfortunately, it looks like filtering the results of Places.PlaceDetectionApi.getCurrentPlace
by the type of place (eg restaurants) is not supported yet. The Place.TYPE_RESTAURANT
you referenced can be used in AutocompleteFilter for GeoDataApi.getAutocompletePredictions
.
Upvotes: 2