Google 地图地理编码在正向 API 和反向 API 中得到不同的结果 - 在某些地址中

Google map geocode getting different result in Forward API and Reverse API - In Some Addresses

转发 API : https://maps.googleapis.com/maps/api/geocode/json?address=1045%20E%2024th%20St,%20Minneapolis,%20MN%2055404&key=YOUR_API_KEY

结果

{
   "results":[
      {
         "address_components":[
            {
               "long_name":"1045",
               "short_name":"1045",
               "types":[
                  "street_number"
               ]
            },
            {
               "long_name":"East 24th Street",
               "short_name":"E 24th St",
               "types":[
                  "route"
               ]
            },
            {
               "long_name":"Phillips",
               "short_name":"Phillips",
               "types":[
                  "neighborhood",
                  "political"
               ]
            },
            {
               "long_name":"Minneapolis",
               "short_name":"Minneapolis",
               "types":[
                  "locality",
                  "political"
               ]
            },
            {
               "long_name":"Hennepin County",
               "short_name":"Hennepin County",
               "types":[
                  "administrative_area_level_2",
                  "political"
               ]
            },
            {
               "long_name":"Minnesota",
               "short_name":"MN",
               "types":[
                  "administrative_area_level_1",
                  "political"
               ]
            },
            {
               "long_name":"United States",
               "short_name":"US",
               "types":[
                  "country",
                  "political"
               ]
            },
            {
               "long_name":"55404",
               "short_name":"55404",
               "types":[
                  "postal_code"
               ]
            },
            {
               "long_name":"3833",
               "short_name":"3833",
               "types":[
                  "postal_code_suffix"
               ]
            }
         ],
         "formatted_address":"1045 E 24th St, Minneapolis, MN 55404, USA",
         "geometry":{
            "location":{
               "lat":44.9589308,
               "lng":-93.2592956
            },
            "location_type":"RANGE_INTERPOLATED",
            "viewport":{
               "northeast":{
                  "lat":44.96027978029149,
                  "lng":-93.25794661970849
               },
               "southwest":{
                  "lat":44.9575818197085,
                  "lng":-93.2606445802915
               }
            }
         },
         "place_id":"EioxMDQ1IEUgMjR0aCBTdCwgTWlubmVhcG9saXMsIE1OIDU1NDA0LCBVU0EiGxIZChQKEgmhxzziqTKzUhEX8ec1BmZglBCVCA",
         "types":[
            "street_address"
         ]
      }
   ],
   "status":"OK"
}

反过来 API,我使用了相同的几何位置纬度和经度

反转API:https://maps.googleapis.com/maps/api/geocode/json?latlng=44.9589308,-93.2592956&key=YOUR_API_KEY

结果

{
   "plus_code":{
      "compound_code":"XP5R+H7 Minneapolis, MN, USA",
      "global_code":"86P8XP5R+H7"
   },
   "results":[
      {
         "address_components":[
            {
               "long_name":"2400",
               "short_name":"2400",
               "types":[
                  "street_number"
               ]
            },
            {
               "long_name":"11th Avenue South",
               "short_name":"11th Ave S",
               "types":[
                  "route"
               ]
            },
            {
               "long_name":"Midtown Phillips",
               "short_name":"Midtown Phillips",
               "types":[
                  "neighborhood",
                  "political"
               ]
            },
            {
               "long_name":"Minneapolis",
               "short_name":"Minneapolis",
               "types":[
                  "locality",
                  "political"
               ]
            },
            {
               "long_name":"Hennepin County",
               "short_name":"Hennepin County",
               "types":[
                  "administrative_area_level_2",
                  "political"
               ]
            },
            {
               "long_name":"Minnesota",
               "short_name":"MN",
               "types":[
                  "administrative_area_level_1",
                  "political"
               ]
            },
            {
               "long_name":"United States",
               "short_name":"US",
               "types":[
                  "country",
                  "political"
               ]
            },
            {
               "long_name":"55404",
               "short_name":"55404",
               "types":[
                  "postal_code"
               ]
            },
            {
               "long_name":"3806",
               "short_name":"3806",
               "types":[
                  "postal_code_suffix"
               ]
            }
         ],
         "formatted_address":"2400 11th Ave S, Minneapolis, MN 55404, USA",
         "geometry":{
            "bounds":{
               "northeast":{
                  "lat":44.9589961,
                  "lng":-93.2589414
               },
               "southwest":{
                  "lat":44.958912,
                  "lng":-93.25912079999999
               }
            },
            "location":{
               "lat":44.958968,
               "lng":-93.2590273
            },
            "location_type":"ROOFTOP",
            "viewport":{
               "northeast":{
                  "lat":44.9603030302915,
                  "lng":-93.25768211970849
               },
               "southwest":{
                  "lat":44.9576050697085,
                  "lng":-93.2603800802915
               }
            }
         },
         "place_id":"ChIJTb-V4qkys1IRukelu4LNRgI",
         "types":[
            "premise"
         ]
      },

这里我得到了不同的反向地址 Google API, 如果我需要在 link 或其他

中添加任何内容,请帮助我

关于您的问题,您应该知道并非所有地址都显示在 Google 数据库中。有时地址只是根据街道名称和街道号码范围等其他数据进行插值,因此 Google 甚至可以预测其数据库中缺失的地址的位置。

当您对某些地址进行地理编码时,您应该检查结果的 location_type 是什么。在您的示例中,location_type 是 RANGE_INTERPOLATED。这意味着 Google 在他们的数据库中没有地址“1045 E 24th St, Minneapolis, MN 55404”的确切 ROOFTOP 地址,并且该位置是插值的。插值位置的另一个明显标志是非常长的位置 ID 值。在您的示例中,它是 EioxMDQ1IEUgMjR0aCBTdCwgTWlubmVhcG9saXMsIE1OIDU1NDA0LCBVU0EiGxIZChQKEgmhxzziqTKzUhEX8ec1BmZglBCVCA.

那么,如果您现在对该插值地址 (44.9589308,-93.2592956) 的坐标进行反向地理编码,会发生什么情况?反向地理编码服务将优先使用现有的 ROOFTOP 地址,并将 return 第一个最接近 location_type ROOFTOP 的结果,然后是其他插值结果。

在您的示例中,有几个结果是 return 的反向地理编码。您可以在我的屏幕截图中看到它们:

第一个结果(标记 1)是“2400 11th Ave S, Minneapolis, MN 55404, USA”,位置类型为 ROOFTOP,第二个(标记 2)是“2408 11th Ave S, Minneapolis, MN 55404, USA” ' 同样是位置类型 ROOFTOP,第三个(标记 3)是 '1005 E 24th St, Minneapolis, MN 55404, USA' 再次是 ROOFTOP,只有第四个结果是 RANGE_INTERPOLATED 地址 '1045 E 24th St, Minneapolis, MN 55404 , 美国'

请注意,您可以要求反向地理编码服务仅提供特定位置类型的结果。例如,您可以说您只对 RANGE_INTERPOLATED 结果感兴趣:

https://maps.googleapis.com/maps/api/geocode/json?latlng=44.9589308%2C-93.2592956&location_type=RANGE_INTERPOLATED&key=YOUR_API_KEY

在这种情况下,反向地理编码的第一个结果将是您的范围内插地址,如我的屏幕截图所示

希望我的回答能解开你的疑惑。