gpt4 book ai didi

android - 如何从适用于 Android 的 Google Places GeoDataApi 解析地址(缺少地址组件)

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:00:44 24 4
gpt4 key购买 nike

我们使用与示例应用类似的 Google Places API 预测。在选择结果时,我们使用以下方法获取预测位置的详细信息:

Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId);

这很好用,我的问题是结果只包含一个字符串作为地址。

使用 JS version of the API 时,结果包含:

"address_components" : [
{
"long_name" : "522",
"short_name" : "522",
"types" : [ "street_number" ]
},
{
"long_name" : "Overtoom",
"short_name" : "Overtoom",
"types" : [ "route" ]
},
{
"long_name" : "Amsterdam-West",
"short_name" : "Amsterdam-West",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "Amsterdam",
"short_name" : "Amsterdam",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Amsterdam",
"short_name" : "Amsterdam",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Noord-Holland",
"short_name" : "NH",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Nederland",
"short_name" : "NL",
"types" : [ "country", "political" ]
},
{
"long_name" : "1054",
"short_name" : "1054",
"types" : [ "postal_code_prefix", "postal_code" ]
}
],

但是在Android 上使用API​​ 时,address_components 中的上述信息丢失了。我如何使用 Google places API 在 Android 上获取此信息?

最佳答案

很遗憾,答案是“你不能。”

Google 不向该 API 的 Android 实现提供结构化响应数据。

您可以尝试解析地址文本,但根据 my answer to a related post ,这远非微不足道:

  1. You figure out a clever way to parse that string. Unfortunately the actual street/suburb/town/province structure is not consistent across different areas (e.g. Cape Town in South Africa has a different sentence structure to Johannesburg in South Africa). So your parsing rules need to be very clever.
  2. You use a different Google API. The JavaScript API provides structured data for the related call. Unfortunately Google recommends against using this technique.

我的一位同事已将此问题记录到 Google:

关于android - 如何从适用于 Android 的 Google Places GeoDataApi 解析地址(缺少地址组件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34381323/

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