Get latitude and longitude from Zipcode
i want fetch latitude and longitude of Zipcode.
i tried like this
<script type="text/javascript">
var geocoder, location1, location2,glatlng1,glatlng2;
var dealerPincodes = ["560042", "560043", "560044", "560054"];
someFunction(dealerPincodes, function() {
// my code
});
function someFunction(dealerPincodes, callback) {
var coords = [];
for(var i = 0; i < dealerPincodes.length; i++) {
alert(dealerPincodes[i]);
Pincode = dealerPincodes[i];
var geocoder = new google.maps.Geocoder();
if (geocoder) {
geocoder.geocode({'address':Pincode}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
coords.push(results[0].geometry.location);
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
alert("Latitude: " + latitude + "\nLongitude: " + longitude);
if(coords.length == dealerPincodes.length) {
if( typeof callback == 'function' ) {
callback();
}
}
}
else {
throw('No results found: ' + status);
}
});
}
}
}
</script>
but its not working properly