Created
November 6, 2012 04:21
-
-
Save mojowen/4022522 to your computer and use it in GitHub Desktop.
Geolocate an array of addresses
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
| <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