gpt4 book ai didi

android - 在 Android 中按类型过滤 Google 地方信息结果

转载 作者:行者123 更新时间:2023-11-29 16:41:16 25 4
gpt4 key购买 nike

我在我的 Android 应用程序中使用 Google Places API,尤其是 PlaceAutocomplete。

我必须过滤结果以仅显示学校。

我看到这个问答似乎是我想要的,但它仅供网络使用: Can Google Places API pull specific types of places, like schools, without a location?

我不知道如何用 Android SDK 做同样的事情...

我试试这个:

val typeFilter = AutocompleteFilter.Builder()
.setTypeFilter(Place.TYPE_SCHOOL)
.build()

val intent = PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
.setFilter(typeFilter)
.build(this)

startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE)

但是没有效果

有什么帮助吗???

谢谢,很棒

最佳答案

不幸的是,地点自动完成不支持过滤器中的详细类型。如果您查看文档,您会看到只有受支持的类型是

  • TYPE_FILTER_ADDRESS
  • TYPE_FILTER_CITIES
  • TYPE_FILTER_ESTABLISHMENT
  • TYPE_FILTER_GEOCODE
  • TYPE_FILTER_NONE
  • TYPE_FILTER_REGIONS

来源:https://developers.google.com/android/reference/com/google/android/gms/location/places/AutocompleteFilter

与 Places API 自动完成网络服务相同的情况:

https://developers.google.com/places/web-service/autocomplete#place_types

Google 问题跟踪器中有一个非常古老的功能请求,用于在适当的位置自动完成添加详细类型过滤器。您可以在此处查看此功能请求:

https://issuetracker.google.com/issues/35820774

随时为它加注星标以添加您的投票并订阅通知。

如果您有兴趣实现与上述问题类似的网络服务调用,请查看 Google map 服务的 Java 客户端:

https://github.com/googlemaps/google-maps-services-java

使用此库,您可以在 Java 中实现文本搜索功能。有点像

GeoApiContext context = new GeoApiContext.Builder()
.apiKey("AIza......")
.build();

TextSearchRequest req = PlacesApi.textSearchQuery(context, "Springfield Elementary");
try {
PlacesSearchResponse resp = req.type(PlaceType.SCHOOL).await();
if (resp.results != null && resp.results.length > 0) {
for (PlacesSearchResult r : resp.results) {
//TODO: implement logic for places
}
}
} catch(Exception e) {
Log.e(TAG, "Error getting places", e);
}

希望对您有所帮助!

关于android - 在 Android 中按类型过滤 Google 地方信息结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50630969/

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