gpt4 book ai didi

Android PlaceFilter 与 Google Places API 的结合使用

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:40:39 26 4
gpt4 key购买 nike

我正在尝试使用 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);

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

最佳答案

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

关于Android PlaceFilter 与 Google Places API 的结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29584266/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com