我使用Google Places API实现自动填充功能。
我注意到Google Places API没有为某些地址返回邮政编码:
其中一个预测:
description = "3rd Avenue, NY, United States";
id = b9ea1b2047021e7b8f4d1e2d2033b4baafcc8d21;
"matched_substrings" = (
{
length = 1;
offset = 0;
}
);
"place_id" = Eh0zcmQgQXZlbnVlLCBOWSwgVW5pdGVkIFN0YXRlcw;
reference = "CjQhAAAAZddDjaWNLgFtHPG-JqwGI9W4kfxDj0DwYLQ9WtzJ8BdKJ-q7qu0YcrGHfdYCs_6-EhB6ZULyxVK-yFVOMmjt17XIGhT76Ln6Cy1sukn0DMKMLiqMADMmbg";
terms = (
{
offset = 0;
value = "3rd Avenue";
},
{
offset = 12;
value = NY;
},
{
offset = 16;
value = "United States";
}
);
types = (
route,
geocode
);
此外,当我打电话给这个地方的详细信息时,它甚至不会返回邮政编码。
结果:
"html_attributions" = (
);
result = {
"address_components" = (
{
"long_name" = "3rd Ave";
"short_name" = "3rd Ave";
types = (
route
);
},
{
"long_name" = Manhattan;
"short_name" = Manhattan;
types = (
"sublocality_level_1",
sublocality,
political
);
},
{
"long_name" = "New York";
"short_name" = NY;
types = (
locality,
political
);
},
{
"long_name" = "New York County";
"short_name" = "New York 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
);
}
);
"adr_address" = "<span class=\"street-address\">3rd Ave</span>, <span class=\"locality\">New York</span>, <span class=\"region\">NY</span>, <span class=\"country-name\">USA</span>";
"formatted_address" = "3rd Ave, New York, NY, USA";
geometry = {
location = {
lat = "40.769058";
lng = "-73.9611034";
};
};
icon = "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png";
id = b9ea1b2047021e7b8f4d1e2d2033b4baafcc8d21;
name = "3rd Ave";
"place_id" = ChIJAScMMupYwokRnhWalEuqcnc;
reference = "CoQBfQAAACR4npz_DDE5pbhlslJYJ6h4obSF9CIvnIvEfySMR_FNLUFCfGGYOM858hmM8_FibAaO0AlA0Qq7EhFqorMoTh6jzknlsXRmwX2sMVSgqGX6YgGmzPPvlqHTOdAuXbWMYuKACZXiiJN4F4xpWmWgwqIXPRKU6qg0f8e3b-N9q5vQEhBHvnjfb7TBlz18IhaVnX1yGhTwAeuiDacEGbUVezjTvMQhXzK1Kw";
scope = GOOGLE;
types = (
route
);
url = "https://maps.google.com/maps/place?q=3rd+Ave,+New+York,+NY,+USA&ftid=0x89c258ea320c2701:0x7772aa4b949a159e";
vicinity = Manhattan;
};
status = OK;
如何使用Google Places API获取邮政编码?
答案 0 :(得分:2)
这些结果可能太大,无法拥有一个独特的邮政编码。如果您反转地理编码返回的位置(不会“使用Google Places API”),它(可能)会有一个邮政编码(至少会返回最精确的结果),但这是否仍然有用仍然是可见