Google Places API PlaceFilter

时间:2015-05-20 19:13:26

标签: android google-places-api

我正在使用适用于Android的Google Places API,并尝试将结果限制为仅显示餐馆。我已经包含了一个PlaceFilter并且似乎是正确的,但似乎没有应用过滤器并提供除餐馆之外的其他结果。见代码:

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();
                    }
                });

任何人都有任何想法如何应用PlaceFilter?

1 个答案:

答案 0 :(得分:2)

目前,PlaceFilter类概述了过滤getCurrentPlace结果的唯一方法:

  

requireOpenNow 如果为true,则仅返回现在打开的地方

     

restrictToPlaceIds 要匹配的特定PlaceIds

这些PlaceIds中的每一个都应该与特定位置匹配。不幸的是,它似乎不支持按地点类型(例如餐馆)过滤Places.PlaceDetectionApi.getCurrentPlace的结果。您引用的Place.TYPE_RESTAURANT可以AutocompleteFilter用于GeoDataApi.getAutocompletePredictions