【问题标题】:Google places api should return only addressGoogle Places api 应该只返回地址
【发布时间】:2015-09-18 14:15:48
【问题描述】:

我使用这个 url 通过 Get 请求获取地址:https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Nov&key=MyKet&types=address

但有时我只得到没有房子的街道,有时我甚至得到城市(如果 input=Minsk 在俄语中:https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%D0%9C%D0%98%D0%9D%D0%A1%D0%9A&key=MyKey&types=address

但我只想得到有房子的街道,因为我正在写出租车应用程序,我只需要完整的地址,如果用户只选择街道是不够的。

所以如果我从 Google Proletarsk street 25, Bern, Switzerland 收到 - 没关系,但如果我从 Google Proletarsk street, Bern, Switzerland 收到 - 就不行了。

当我从谷歌得到街道和地址的回复时,它总是返回相同的类型

types =     (
        route,
        geocode
    );

所以我什至无法区分返回值是街道还是完整地址。

你能给我什么建议吗?

【问题讨论】:

  • 我认为你使用了错误的 API Key。
  • 不,我使用我的 API Key,但我不能在这里写它,因为它不是公开的。如果我使用了错误的 API 密钥,我将不会得到任何结果。但我确实得到了结果,我只是想确保我得到了房子的街道(不仅仅是街道)
  • 在此期间您找到解决问题的方法了吗?
  • 我刚刚找到了一个解决方法:我使用了地址,但是在获得返回值后我手动检查了格式。因此,如果用户检查了没有家的行,我只是说他这不是正确的行。但是您可以在将结果显示给用户之前手动过滤结果

标签: ios iphone google-maps google-maps-api-3


【解决方案1】:

根据您描述的用例,听起来您使用了错误的 API。

如果您有地址并且希望 Google 地图为您解析并返回额外信息,您应该使用 the Geocoding API。您可以确定结果是否有street_number,以便您可以判断结果是否包含完整地址。例如:
https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA
会给你这样的结果:

    {
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "1600",
               "short_name" : "1600",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Amphitheatre Parkway",
               "short_name" : "Amphitheatre Pkwy",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Mountain View",
               "short_name" : "Mountain View",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Santa Clara County",
               "short_name" : "Santa Clara County",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "California",
               "short_name" : "CA",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "94043",
               "short_name" : "94043",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
         "geometry" : {
            "location" : {
               "lat" : 37.4223455,
               "lng" : -122.0841893
            },
            "location_type" : "ROOFTOP",
            "viewp.....

它给你一个street_number,所以你可以知道它是一个完整的地址。

【讨论】:

  • 不,因为如果我从 google 获得 5 个包含街道和地址的结果,我无法通过其他请求检查所有这 5 个结果
猜你喜欢
  • 2013-04-14
  • 1970-01-01
  • 1970-01-01
  • 2013-01-17
  • 2015-12-30
  • 2017-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多