gmap api geocode zipcode saudi arabia 未按预期工作

gmap api geocode zipcode saudi arabia not working as expected

使用 Google 地图 API 获取邮政编码的边界和坐标。

在对沙特阿拉伯 (SA) 区域的地址进行地理编码时,当对沙特阿拉伯 (SA) 的邮政编码进行地理编码时,地理编码器的结果具有指向 2517 荷兰海牙的地址

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "2517",
               "short_name" : "2517",
               "types" : [ "postal_code", "postal_code_prefix" ]
            },
            {
               "long_name" : "The Hague",
               "short_name" : "The Hague",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "The Hague",
               "short_name" : "The Hague",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "South Holland",
               "short_name" : "ZH",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Netherlands",
               "short_name" : "NL",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "2517 The Hague, Netherlands",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 52.0958783,
                  "lng" : 4.3007563
               },
               "southwest" : {
                  "lat" : 52.0773935,
                  "lng" : 4.2732776
               }
            },
            "location" : {
               "lat" : 52.0847639,
               "lng" : 4.2801843
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 52.0958783,
                  "lng" : 4.3007563
               },
               "southwest" : {
                  "lat" : 52.0773935,
                  "lng" : 4.2732776
               }
            }
         },
         "place_id" : "ChIJI9DHzc6wxUcR1s1th0GbWgQ",
         "types" : [ "postal_code", "postal_code_prefix" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "2517",
               "short_name" : "2517",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "Russell Vale",
               "short_name" : "Russell Vale",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Wollongong City Council",
               "short_name" : "Wollongong",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "New South Wales",
               "short_name" : "NSW",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Australia",
               "short_name" : "AU",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Russell Vale NSW 2517, Australia",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : -34.3338503,
                  "lng" : 150.9245951
               },
               "southwest" : {
                  "lat" : -34.3654418,
                  "lng" : 150.8740632
               }
            },
            "location" : {
               "lat" : -34.3454996,
               "lng" : 150.9016476
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : -34.3338503,
                  "lng" : 150.9245951
               },
               "southwest" : {
                  "lat" : -34.3654418,
                  "lng" : 150.8740632
               }
            }
         },
         "place_id" : "ChIJSaEBIk8eE2sRQIa6P2t9ARw",
         "postcode_localities" : [ "Russell Vale", "Woonona" ],
         "types" : [ "postal_code" ]
      }
   ],
   "status" : "OK"
}

由于结果与沙特阿拉伯无关,在api中添加了国家限制。但结果有 Partial ResultsTrue,指的是结果不准确,结果有只有沙特阿拉伯位置的默认值

https://maps.googleapis.com/maps/api/geocode/json?address=2517&components=country:SA

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Saudi Arabia",
               "short_name" : "SA",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Saudi Arabia",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 32.1542839,
                  "lng" : 55.6666999
               },
               "southwest" : {
                  "lat" : 16.379528,
                  "lng" : 34.5489978
               }
            },
            "location" : {
               "lat" : 23.885942,
               "lng" : 45.079162
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 32.1542839,
                  "lng" : 55.6666999
               },
               "southwest" : {
                  "lat" : 16.379528,
                  "lng" : 34.5489978
               }
            }
         },
         "partial_match" : true,
         "place_id" : "ChIJQSqV5z-z5xURm7YawktQYFk",
         "types" : [ "country", "political" ]
      }
   ],
   "status" : "OK"
}

但是当 Street/Region 的地址添加了 Zipcode 时,地理编码就起作用了 https://maps.googleapis.com/maps/api/geocode/json?address=2517+Ar+Riyadh&components=country:SA

有没有办法强制 Gmap api 对沙特阿拉伯国家/地区唯一具有邮政编码的地址进行地理编码,结果是准确的坐标和边界?

沙特阿拉伯的邮政编码覆盖范围似乎不太好。

您可以使用 component filtering 搜索邮政编码,但是如果缺少邮政编码,您通常会得到 ZERO_RESULTS。

例如,

https://maps.googleapis.com/maps/api/geocode/json?components=postal_code%3A12631%7Ccountry%3ASA

returns 一个邮政编码,但是

https://maps.googleapis.com/maps/api/geocode/json?components=postal_code%3A31433%7Ccountry%3ASA

returns ZERO_RESULTS.

对于缺少的邮政编码,您可以使用 maps.google.com 右下角的 "Send Feedback" link。

https://support.google.com/maps/answer/162873

希望对您有所帮助!