微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Android PlaceFilter与Google Places API一起使用

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

我正在使用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)添加到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);

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

解决方法

我一直在寻找同样的事情.不幸的是,它似乎不可能 – PlaceFilter发生id,而不是类型. PlaceFilter类是最终的,因此它无法扩展(我讨厌API编写器最终完成类时,几乎从来没有理由这样做).在结果返回后,您需要实际进行调用并通过循环进行过滤.

原文地址:https://www.jb51.cc/android/318420.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐