我想询问如何从新的Google地方api(https://developers.google.com/places/android/start)
获取附近有过滤器类型的地方(例如:购物中心,银行)这里是我的代码(我已经在循环条件中添加了一些替代方法),但我想从PlaceFilter中过滤类型而不是在循环条件中。
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();
}
});
请帮助,非常感谢
答案 0 :(得分:2)
我认为你正在尝试做这样的事情。
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