我想使用Google Maps API获取邮政编码的坐标。
我正在使用此文档:https://developers.google.com/maps/documentation/geocoding/intro?csw=1
当我现在想要搜索邮政编码1200(瑞士日内瓦)时,我使用此URL:
https://maps.google.com/maps/api/geocode/json?region=ch&components=postal_code:1200
我得到了很多不同的结果,但在瑞士却没有(结果是在问题的最后)。看起来region参数根本不起作用,因为我在其他国家获得了结果。
当我搜索1201(也是日内瓦)时,它有效。
知道为什么吗?我宁愿得不到任何结果然后错误的结果(在其他国家的结果)
{
"results" : [
{
"address_components" : [
{
"long_name" : "1200",
"short_name" : "1200",
"types" : [ "postal_code" ]
},
{
"long_name" : "Region Brüssel-Hauptstadt",
"short_name" : "Region Brüssel-Hauptstadt",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Belgien",
"short_name" : "BE",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "1200, Belgien",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 50.86307189999999,
"lng" : 4.4629024
},
"southwest" : {
"lat" : 50.8337598,
"lng" : 4.3999935
}
},
"location" : {
"lat" : 50.850308,
"lng" : 4.4278228
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 50.86307189999999,
"lng" : 4.4629024
},
"southwest" : {
"lat" : 50.8337598,
"lng" : 4.3999935
}
}
},
"place_id" : "ChIJNa8iqqHcw0cRG4NyYbv66KY",
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "1200",
"short_name" : "1200",
"types" : [ "postal_code" ]
},
{
"long_name" : "Wien",
"short_name" : "Wien",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Wien",
"short_name" : "Wien",
"types" : [ "postal_town" ]
},
{
"long_name" : "Wien",
"short_name" : "Wien",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Österreich",
"short_name" : "AT",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "1200 Wien, Österreich",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 48.2646423,
"lng" : 16.4007913
},
"southwest" : {
"lat" : 48.2252299,
"lng" : 16.3618448
}
},
"location" : {
"lat" : 48.235668,
"lng" : 16.373098
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 48.2646423,
"lng" : 16.4007913
},
"southwest" : {
"lat" : 48.2252299,
"lng" : 16.3618448
}
}
},
"place_id" : "ChIJs0PDoUQGbUcRI9VvmpZbVzQ",
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "1200",
"short_name" : "1200",
"types" : [ "postal_code", "postal_code_prefix" ]
},
{
"long_name" : "Lissabon",
"short_name" : "Lissabon",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Lissabon",
"short_name" : "Lissabon",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Portugal",
"short_name" : "PT",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "1200 Lissabon, Portugal",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 38.7177413,
"lng" : -9.1387655
},
"southwest" : {
"lat" : 38.7006072,
"lng" : -9.168078299999999
}
},
"location" : {
"lat" : 38.7096083,
"lng" : -9.1539178
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 38.7177413,
"lng" : -9.1387655
},
"southwest" : {
"lat" : 38.7006072,
"lng" : -9.168078299999999
}
}
},
"place_id" : "ChIJT3JAUYI0GQ0R4Nc7DsHrABw",
"types" : [ "postal_code", "postal_code_prefix" ]
},
{
"address_components" : [
{
"long_name" : "1200",
"short_name" : "1200",
"types" : [ "postal_code" ]
},
{
"long_name" : "Mbombela",
"short_name" : "Mbombela",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Mbombela",
"short_name" : "Mbombela",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Ehlanzeni",
"short_name" : "Ehlanzeni",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Mpumalanga",
"short_name" : "MP",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Südafrika",
"short_name" : "ZA",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Mbombela, 1200, Südafrika",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -25.434559,
"lng" : 31.035606
},
"southwest" : {
"lat" : -25.5273621,
"lng" : 30.9615131
}
},
"location" : {
"lat" : -25.4922163,
"lng" : 31.0048384
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -25.434559,
"lng" : 31.035606
},
"southwest" : {
"lat" : -25.5273621,
"lng" : 30.9615131
}
}
},
"place_id" : "ChIJC-Upoo1J6B4RbhfORqGdY2s",
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "1200",
"short_name" : "1200",
"types" : [ "postal_code" ]
},
{
"long_name" : "København K",
"short_name" : "København K",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "København",
"short_name" : "København",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Dänemark",
"short_name" : "DK",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "1200 København K, Dänemark",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 55.6788537,
"lng" : 12.581048
},
"southwest" : {
"lat" : 55.6774083,
"lng" : 12.5790574
}
},
"location" : {
"lat" : 55.6780957,
"lng" : 12.5799054
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 55.6794799802915,
"lng" : 12.5814016802915
},
"southwest" : {
"lat" : 55.6767820197085,
"lng" : 12.5787037197085
}
}
},
"place_id" : "ChIJuYvG1hZTUkYREL3-tlYomQk",
"types" : [ "postal_code" ]
}
],
"status" : "OK"
}
答案 0 :(得分:2)
与 duncan 一样,region code只会影响(而非完全限制)地理编码器的结果。要了解更多信息,请查看region biasing。
如果您想在某个国家/地区使用特定结果,请使用 component = country 而不是某个地区。
我尝试在瑞士国家/地区申请 postal_code:1200 。我得到零结果。因此,请确保您使用的请求有效。
https://maps.google.com/maps/api/geocode/json?components=postal_code:1200|country:CH
如果我尝试 postal_code:1201 ,我会得到您想要的具体结果。
https://maps.google.com/maps/api/geocode/json?components=postal_code:1201|country:CH
如果您确定 postal_code:1200 在瑞士是有效的邮政编码,则可能该邮政编码不被Google地图视为瑞士日内瓦的邮政编码。
还要尝试检查我回答的相关SO question。