Created
May 30, 2012 17:16
-
-
Save rojan/2837725 to your computer and use it in GitHub Desktop.
converts zip_code to lat long and formatted address using google api.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://developers.google.com/maps/faq#geocoder_limit | |
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> | |
<script> | |
/* | |
*cannot send many query at a time. google api has query limit. | |
*https://developers.google.com/maps/faq#geocoder_limit | |
*/ | |
var geocoder = new google.maps.Geocoder(); | |
var zip_code = [ | |
//'10002', '10003', '10004', | |
//'10005', '10006', '10007', | |
//'10009', '10011', '10012', | |
//'10013', '10014', '10016', | |
//'10017', '10018', '10019', | |
//'10020', '10021', '10022', | |
//'10023', '10025', '10026', | |
//'10028', '10029', '10036', | |
'10038', '10280', '19010' | |
]; | |
for (var i=0; i < zip_code.length; i++) { | |
// console.log(i); | |
geocoder.geocode({'address': zip_code[i]}, | |
function(result, status){ | |
if (status == google.maps.GeocoderStatus.OK) { | |
console.log("\['"+result[0].geometry.location.lat()+ | |
"'"+ ", "+"'"+ result[0].geometry.location.lng()+ | |
"'"+", "+"'"+result[0].formatted_address+"'\]" | |
); | |
} | |
}); | |
} | |
//output : ['40.7075907', '-74.02266780000002', 'Manhattan, NY 10280, USA'] | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment