Reputation: 32449
I use Google Places API to implement autocomplete.
I noticed that Google Places API doesn't return zip codes for some addresses:
One of predictions:
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
);
Moreover, it even doesn't return postal code, when I call details of this place.
Result:
"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;
How do I get postal code with using Google Places API?
Upvotes: 1
Views: 6029
Reputation: 161334
Those results are probably too big to have a single unique postal code. If you reverse geocode the returned location (which wouldn't be "using the Google Places API"), it will (probably) have a postal code (at least the most precise result returned will), but whether that is useful remains to be seen.
Upvotes: 2