问题描述
我想问一下如何从新的Google Places API( https://developers.google.com/places/android/start )
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)
这里是我的代码(我已经在循环条件下添加了一些替代方法),但是我想从PlaceFilter而不是在循环条件下过滤类型.
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();
}
});
请帮助,非常感谢
推荐答案
我认为您正在尝试执行此类操作.
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
}
您可以使用
filters.add(Place.<MORE FILTERS>); //example TYPE_AIRPORT
在此处查看更多过滤器类型 https://developers.google.com/places/supported_types
Check here for more filter typeshttps://developers.google.com/places/supported_types
这篇关于Google Places API Android中的PlaceFilter位置类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!