在大多数(如果不是所有)国家/地区,每个地区(address_components - “types”:[“locality”,“political”])至少有一个邮政编码,较大的城市有多个邮政编码(address_components - “types”:[“postal_code” " ])。但大多数地区只有一个邮政编码。当使用只有一个邮政编码的地区的 Google Geocode API 时,地区(例如:“richterswil”)和地区加上相应的邮政编码(例如:“8805+richterswil”)返回不同的坐标。这在我看来是出乎意料的,并使某些任务比应有的复杂得多(想想为用户输入的地方查找坐标 - 有些会包括邮政编码,有些则不会,这会导致本质上完全相同的事物出现不同的坐标)。这是什么原因以及如何正确处理它(在所有情况下获取相同的坐标,而无需在输入字段中请求邮政编码)?
-我发现,当在 Geocode API 调用中不包括邮政编码时,搜索地点的坐标与谷歌在地图(标签)上显示地区名称的位置完全相同。- 包含邮政编码时,坐标似乎随机移动了 500-1000 米。
我已经使用这些 API 调用进行实验(添加您自己的 API 密钥):
- 没有邮政编码:
- 包含的邮政编码:
- 回复(无邮政编码):
{
"results" : [
{
"address_components" : [
{
"long_name" : "Richterswil",
"short_name" : "Richterswil",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Horgen",
"short_name" : "Horgen",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Zürich",
"short_name" : "ZH",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Schweiz",
"short_name" : "CH",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Richterswil, Schweiz",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 47.2335482,
"lng" : 8.7409239
},
"southwest" : {
"lat" : 47.18228,
"lng" : 8.661769999999999
}
},
"location" : {
"lat" : 47.2053892,
"lng" : 8.7070691
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 47.2335482,
"lng" : 8.7409239
},
"southwest" : {
"lat" : 47.18228,
"lng" : 8.661769999999999
}
}
},
"place_id" : "ChIJO0JjJ6CxmkcRLdEGdhgDTXg",
"types" : [ "locality", "political" ]
}
],
"status" : "OK"
}
- 回复(包括邮政编码):
{
"results" : [
{
"address_components" : [
{
"long_name" : "8805",
"short_name" : "8805",
"types" : [ "postal_code" ]
},
{
"long_name" : "Richterswil",
"short_name" : "Richterswil",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Horgen",
"short_name" : "Horgen",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Zürich",
"short_name" : "ZH",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Schweiz",
"short_name" : "CH",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "8805 Richterswil, Schweiz",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 47.2201589,
"lng" : 8.713399599999999
},
"southwest" : {
"lat" : 47.1962357,
"lng" : 8.679173199999999
}
},
"location" : {
"lat" : 47.2097073,
"lng" : 8.696259999999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 47.2201589,
"lng" : 8.713399599999999
},
"southwest" : {
"lat" : 47.1962357,
"lng" : 8.679173199999999
}
}
},
"place_id" : "ChIJ-Ub3o--xmkcRNqm0YtWPm1U",
"types" : [ "postal_code" ]
}
],
"status" : "OK"
}