Google Places API Web服务与Geocode API的结果不同

时间:2018-01-25 22:43:53

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

使用以下地址时:

  

" 107-25 CONTINENTAL AVE Forest Hills NY 11375"

我得到两个不同的街道号码。

为什么会这样?

Google Maps Geocoding API

获取https://maps.googleapis.com/maps/api/geocode/json?address=

返回

         "address_components" : [
            {
               "long_name" : "107-12",
               "short_name" : "107-12",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Continental Avenue",
               "short_name" : "Continental Ave",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Forest Hills",
               "short_name" : "Forest Hills",
               "types" : [ "neighborhood", "political" ]
            },
            {
               "long_name" : "Queens",
               "short_name" : "Queens",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "Queens County",
               "short_name" : "Queens County",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "NY",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "11375",
               "short_name" : "11375",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "107-12 Continental Ave, Forest Hills, NY 11375, USA",

上使用相同的地址时

Google Places API网络服务

获取https://maps.googleapis.com/maps/api/place/js/PlaceService.GetPlaceDetails

返回:

  "address_components" : [
     {
        "long_name" : "107",
        "short_name" : "107",
        "types" : [ "street_number" ]
     },
     {
        "long_name" : "Continental Avenue",
        "short_name" : "Continental Ave",
        "types" : [ "route" ]
     },
     {
        "long_name" : "Forest Hills",
        "short_name" : "Forest Hills",
        "types" : [ "neighborhood", "political" ]
     },
     {
        "long_name" : "Queens",
        "short_name" : "Queens",
        "types" : [ "sublocality_level_1", "sublocality", "political" ]
     },
     {
        "long_name" : "Queens County",
        "short_name" : "Queens County",
        "types" : [ "administrative_area_level_2", "political" ]
     },
     {
        "long_name" : "New York",
        "short_name" : "NY",
        "types" : [ "administrative_area_level_1", "political" ]
     },
     {
        "long_name" : "United States",
        "short_name" : "US",
        "types" : [ "country", "political" ]
     },
     {
        "long_name" : "11375",
        "short_name" : "11375",
        "types" : [ "postal_code" ]
     }
  ]

1 个答案:

答案 0 :(得分:0)

除了简要提到的内容之外,两个不同的输出 - 我们实际上是在谈论一个不会影响结果的可忽略的数值 - 表明这两个API旨在解决不同的目的。

地理编码是关于将人类可读地址转换为数字坐标,它应该用于complete / unambiguous addresses.注意ROOFTOPS返回结果的精度。我们在这里看到的误差约为0.11米。

这就像问谷歌:" 嘿谷歌,给我这个字符串最相关的地址"

相反,

Places API ...(对于许多人来说,这可能不是那么明显)

  

允许您查询各种类别的地点信息,   如:场所,突出的兴趣点,地理位置   地点,和更多

这就像问:" 嘿谷歌,这里有一个字符串,返回这些类别中的所有内容以及更多"。换句话说,就像收到一堆混合的东西......

反直觉地,我们可以推断出传递给Places API的字符串中必定存在某些内容,使服务器将连字符后的第二个数字转换为"稍微"不同的数字,然后返回它。