Wathek LOUED
unread,Sep 1, 2010, 6:12:13 PM9/1/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google Maps JavaScript API v3
Hi everyone,
I need some help I'd like to get the postal code of some regions using
the latitude and the longitude of that place I know I've to use the
reverse geocoding and that's what I've been using but the problem is
to find the postal code from the returned answer here's the code I'm
using :
function codeLatLng(latlng) {
var input = latlng;
var latlngStr = input.split(",",2);
var lat = parseFloat(latlngStr[0]);
var lng = parseFloat(latlngStr[1]);
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
document.getElementById("airports").innerHTML+="<div
id='airport'><b>Lattitude, Longitude:</b>" + latlng + "<b>Country :</
b>" + results[0].address_components[6].long_name + "<b>Postal Code : </
b>" + results[0].address_components[7].long_name + "</div>";
}
} else {
alert("Geocoder failed due to: " + status);
}
}
but the problem is that not always
results[0].address_components[7].long_name contains the postal code.
So do you know how can I retrieve the postal code ?
Thank you
Sincerely
Wathek