Google Places API Picker仅显示某些类型的地点 [英] Google Places API Picker display Only Certain Types of Places

查看:103
本文介绍了Google Places API Picker仅显示某些类型的地点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作某些需要用户选择地点的android应用程序。我计划使用Google地点API.Link: https://developers.google.com/places/android/

这个API提供了通过Place Picker提供的很好的方法。 https://developers.google.com/places/android/placepicker



现在假设我只想显示食物类型(餐厅,酒店等)的用户位置。使用Places Browser API可以通过在请求中添加type = restraunts属性来完成。

有没有一种方法可以使用Google Places Picker for android仅显示特定类型的地点?

解决方案

我们在2017年,显然这个功能还没有实现。



即便如此,您可以检查在activityResult上选择的地方并使用它。在我的情况下,我希望应用程序只接受医院和相关服务,所以代码如下:

  @Override 
protected void onActivityResult(int requestCode,int resultCode,Intent data){
// ...
boolean isAnHospital = false;
selectedplace = PlacePicker.getPlace(this,data);
for(int i:selectedplace.getPlaceTypes()){
if(i == Place.TYPE_DOCTOR || i == Place.TYPE_HEALTH || i == Place.TYPE_HOSPITAL){
isAnHospital = true;
休息;



if(isAnHospital){
//正确的地点类型
} else {
//告诉用户选择一个合适的地方
}

希望它能以某种方式提供帮助。对不起英文不好。


I am making certain android app that requires user to choose a place. I am planning to user google places API.Link: https://developers.google.com/places/android/

This API gives gives nice way to do so through through Place Picker. https://developers.google.com/places/android/placepicker

Now suppose I want to only show user places of food type (restaurant, hotel etc.) . Using Places Browser API this can be done by adding "type=restraunts" attribute in the requests.

Is there a way to show only places of certain types using the Google Places Picker for android ?

解决方案

We are in 2017 and apparently this feature is still not implemented yet.

Even so, you can check the type(s) of the selected place on the activityResult and use it. In my case, I wanted the app only accept Hospitals and related services, so here's the code:

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//...
boolean isAnHospital = false;
selectedplace = PlacePicker.getPlace(this, data);
for (int i : selectedplace.getPlaceTypes()) {
    if (i == Place.TYPE_DOCTOR || i == Place.TYPE_HEALTH || i == Place.TYPE_HOSPITAL) {
                        isAnHospital = true;
                        break;
                    }
                }

if(isAnHospital){ 
    //Right type of place
}else{
    //Tell to the user to select an appropriate place 
      }           

Hope it helps in some way. Sorry for the bad english.

这篇关于Google Places API Picker仅显示某些类型的地点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆