Android PlaceFilter与Google Places API的配合使用 [英] Android PlaceFilter usage with Google Places API

查看:64
本文介绍了Android PlaceFilter与Google Places API的配合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Google Places API,但我希望将搜索过滤为仅健身房类型.

I am trying to use the Google Places API and I would like to filter my search to only gym types.

我正在使用 https://developers.google.com/places/

public void onPickButtonClick(View v) {
// Construct an intent for the place picker
try {
    PlacePicker.IntentBuilder intentBuilder =
        new PlacePicker.IntentBuilder();
    Intent intent = intentBuilder.build(this);
    // Start the intent by requesting a result,
    // identified by a request code.
    startActivityForResult(intent, REQUEST_PLACE_PICKER);

} catch (GooglePlayServicesRepairableException e) {
    // ...
} catch (GooglePlayServicesNotAvailableException e) {
    // ...
}
}

@Override
protected void onActivityResult(int requestCode,
    int resultCode, Intent data) {

if (requestCode == REQUEST_PLACE_PICKER
    && resultCode == Activity.RESULT_OK) {

    // The user has selected a place. Extract the name and address.
    final Place place = PlacePicker.getPlace(data, this);

    final CharSequence name = place.getName();
    final CharSequence address = place.getAddress();
    String attributions = PlacePicker.getAttributions(data);
    if (attributions == null) {
        attributions = "";
    }

    mViewName.setText(name);
    mViewAddress.setText(address);
    mViewAttributions.setText(Html.fromHtml(attributions));

} else {
    super.onActivityResult(requestCode, resultCode, data);
}
}

我试图做的是创建一个如下所示的过滤器,并以某种方式将其(placeFilter)添加到意图中.

What I was trying to do was to create a filter like below and somehow add that (placeFilter) to the intent.

PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
PlaceFilter placeFilter;
ArrayList<String> restictToGyms = new ArrayList<>();
restictToGyms.add("44");
placeFilter = new PlaceFilter(false, restictToGyms);
intent.SOMEHOWADD(placeFilter);
Intent intent = intentBuilder.build(this);

但是我不确定如何将该过滤器添加到意图中.实际上,我不确定这是否是正确的方法.任何指针将不胜感激.谢谢!

But I am not sure how to add this filter to the intent. In fact I am not sure if this is the right way of doing it. Any pointers will be appreciated. Thanks!

推荐答案

我一直想做同样的事情.不幸的是,这似乎不太可能-PlaceFilter会使用场所ID,而不是类型. PlaceFilter类是final类,因此无法扩展(我讨厌在API编写者将类定为final类时,几乎从来没有理由这样做).返回结果后,您实际上需要进行调用并通过循环进行过滤.

I've been looking to do the same thing. Unfortunately it doesn't seem possible- the PlaceFilter takes place ids, not types. The class PlaceFilter is final so it cannot be extended (I hate it when API writers make classes final, there's almost never a reason to do it). You need to actually make the call and do the filtering via a loop after the result returns.

这篇关于Android PlaceFilter与Google Places API的配合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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