如何限制Google Places Android API仅返回健身房?

如何限制Google Places Android API仅返回健身房?,android,google-places-api,Android,Google Places Api,当使用Google Places Android API时,该API通常会获取用户的位置并返回附近位置的列表。我怎样才能将此列表仅限于健身房?虽然web解决方案很容易获得,但我似乎找不到如何在Android上实现它 这是我当前的代码: public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCr

当使用Google Places Android API时,该API通常会获取用户的位置并返回附近位置的列表。我怎样才能将此列表仅限于健身房?虽然web解决方案很容易获得,但我似乎找不到如何在Android上实现它

这是我当前的代码:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    int PLACE_PICKER_REQUEST = 1;
    PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();

    try {
        startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
    } catch (GooglePlayServicesRepairableException e) {
        e.printStackTrace();
    } catch (GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();
    }

    ArrayList<Integer> types = new ArrayList<>();
    types.add(Places.TYPE_GYM);
    for(PlaceLikelihood likelihood : result) {
        if(hasMatchingType(result.getPlace(), types)) {
            //This is a gym, do whatever you need to here
        }
    }
}


    private boolean hasMatchingType (Place place, List < Integer > allowedTypes){
        List<Integer> types = place.getPlaceTypes();
        for (int type : types) {
            if (allowedTypes.contains(type)) {
                return true;
            }
        }
        return false;
    }


    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);



@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
}
public类MainActivity扩展了AppCompatActivity{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar Toolbar=(Toolbar)findViewById(R.id.Toolbar);
设置支持操作栏(工具栏);
int PLACE\u PICKER\u REQUEST=1;
PlacePicker.IntentBuilder生成器=新的PlacePicker.IntentBuilder();
试一试{
startActivityForResult(builder.build(this),PLACE\u PICKER\u REQUEST);
}捕获(谷歌游戏服务可修复例外){
e、 printStackTrace();
}捕获(谷歌PlayServicesNotAvailableException){
e、 printStackTrace();
}
ArrayList类型=新的ArrayList();
类型.添加(地点.类型\健身房);
对于(地点可能性:结果){
if(hasMatchingType(result.getPlace(),types)){
//这是一个健身房,在这里做任何你需要做的事
}
}
}
私有布尔hasMatchingType(Place,ListallowedTypes){
列表类型=place.getPlaceTypes();
for(int类型:类型){
if(allowedTypes.contains(类型)){
返回true;
}
}
返回false;
}
FloatingActionButton fab=(FloatingActionButton)findViewById(R.id.fab);
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(右菜单菜单菜单主菜单);
返回true;
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
//处理操作栏项目单击此处。操作栏将
//自动处理Home/Up按钮上的点击,只要
//在AndroidManifest.xml中指定父活动时。
int id=item.getItemId();
//noinspection SimplifiableIf语句
if(id==R.id.action\u设置){
返回true;
}
返回super.onOptionsItemSelected(项目);
}
}

请参阅请参阅