PlaceFilter Place Type from Google Places API Android

爷,独闯天下 提交于 2019-12-23 00:53:30

问题


I want to ask how to get nearby Places with filter type (Example: shopping mall, bank) from new google places api (https://developers.google.com/places/android/start)

Here my code (I already add some alternative in loop conditions), but I want to filter types from PlaceFilter not in loop conditions.

PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
            .getCurrentPlace(mGoogleApiClient, null);
    result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
        @Override
        public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
            for (PlaceLikelihood placeLikelihood : likelyPlaces) {
                list = placeLikelihood.getPlace().getPlaceTypes();
                for(int i = 0; i < list.size(); i++)
                {
                    if(list.get(i) == Place.TYPE_SHOPPING_MALL) {
                        Log.i(TAG, String.format("Place '%s' has likelihood: %g",
                                placeLikelihood.getPlace().getName(),
                                placeLikelihood.getLikelihood()));
                    }
                }
            }
            likelyPlaces.release();
        }
    });

Please help, Many thanks


回答1:


I think you are trying to do something like this.

     List<Integer> filters=new ArrayList<>();
     filters.add(Place.TYPE_ESTABLISHMENT); 
     AutocompleteFilter autocompleteFilter=AutocompleteFilter.create(filters);
     PendingResult<AutocompletePredictionBuffer> pendingResult=Places
         .GeoDataApi
         .getAutocompletePredictions(sGoogleApiClient,"delhi", rectangleLyon, autocompleteFilter);
 //rectangleLyon is LatLngBounds, to remove filters put autocompletefilter as null 
 // Second parameter(as String "delhi") is your search query
     AutocompletePredictionBuffer autocompletePredictionBuffer=pendingResult.await(10, TimeUnit.SECONDS);
     Status status=autocompletePredictionBuffer.getStatus();
     Iterator<AutocompletePrediction> iterator=autocompletePredictionBuffer.iterator();

        while (iterator.hasNext()){
            AutocompletePrediction autocompletePrediction=iterator.next();
            // do something
        }          

You can add more filters using

filters.add(Place.<MORE FILTERS>); //example TYPE_AIRPORT

Check here for more filter types https://developers.google.com/places/supported_types



来源:https://stackoverflow.com/questions/29574649/placefilter-place-type-from-google-places-api-android

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