Skip to content

Instantly share code, notes, and snippets.

@mojowen
Created November 6, 2012 04:21
Show Gist options
  • Select an option

  • Save mojowen/4022522 to your computer and use it in GitHub Desktop.

Select an option

Save mojowen/4022522 to your computer and use it in GitHub Desktop.
Geolocate an array of addresses
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
var addresses = [ ], // Addresses you want matched
fixed = [ ], // Where they'll get put eventually
g = new google.maps.Geocoder
function newAddress(address) {
var theaddress = address || addresses.shift()
function newAddress(address) {
var theaddress = address || addresses.shift()
g.geocode( { address: theaddress }, function(response) {
try { if( response.length > 0 ) {
fixed.push( theaddress+"\t"+response[0].geometry.location.toString() );
console.log( theaddress );
setTimeout( function() { newAddress(); }, 1500 );
} else setTimeout( function() { newAddress( theaddress ); }, 2000 ); } catch(e) { setTimeout( function() { newAddress(); }, 2000 ); }
});
}}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment