【问题标题】:Android PlaceFilter usage with Google Places APIAndroid PlaceFilter 与 Google Places API 的使用
【发布时间】:2015-04-11 23:33:10
【问题描述】:

我正在尝试使用 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) 添加到意图中。

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);

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

【问题讨论】:

标签: android google-maps-android-api-2 google-places-api


【解决方案1】:

我一直在寻求做同样的事情。不幸的是,这似乎不可能 - PlaceFilter 发生地点 id,而不是类型。 PlaceFilter 类是 final 的,因此它不能被扩展(当 API 编写者将类设为 final 时,我讨厌它,几乎没有理由这样做)。您需要在结果返回后实际进行调用并通过循环进行过滤。

【讨论】:

    【解决方案2】:

    【讨论】:

    • 我已经查看了该链接。事实上,这就是我得到 restictToGyms.add("44"); 的方式。因为 Place.TYPE_GYM 是 44。我需要的是如何将它添加到意图中,以便谷歌地图只返回 TYPE_GYM 结果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 2014-03-18
    • 1970-01-01
    • 2011-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多