Google Maps Geocoder: Return postal_code
Date : March 29 2020, 07:55 AM
Hope that helps Look at my example: http://jsfiddle.net/nEKMK/o is your object. if (o.results[0].address_components) {
for (var i in o.results[0].address_components) {
if (typeof(o.results[0].address_components[i]) === "object" && o.results[0].address_components[i].types[0] == "postal_code") {
var result = o.results[0].address_components[i].long_name;
}
}
}
if (!result) {
alert("Error, there is no postal code");
} else {
alert(result);
}
|
Getting postal_code value from JSON results
Date : March 29 2020, 07:55 AM
Hope this helps Also note, "return" doesn't work. It's a asynchronous function. So by the time your function runs, the parent function has finished. $.each(results[0].address_components, function(componentIndex, componentValue) {
if ($.inArray("postal_code", componentValue.types)) {
doSomeThingWithPostcode(componentValue.long_name);
}
});
function doSomeThingWithPostcode(postcode) {
$('#input').attr('value',postcode);
}
|
Google Geocode api not returning postal_code for some 'direct hit' addresses
Date : March 29 2020, 07:55 AM
I hope this helps . There are two points you should be aware regarding the sample request for '34 new street, Green road, Carlow'.
|
Google places api only include results that have postal_code
Date : March 29 2020, 07:55 AM
I hope this helps . It's not currently possible to filter places from Place Autocomplete predictions on postal codes only. However, there is an open feature request in Google's Issue Tracker which I suggest starring to increase visibility and subscribe to future notifications:
|
How do you get the postal_code using the Geocoder gem in Ruby on Rails?
Date : March 29 2020, 07:55 AM
|