Google Places API PlaceFilter

℡╲_俬逩灬. 提交于 2019-12-11 12:18:49

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/30358460/google-places-api-placefilter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!