Created
September 24, 2013 18:37
-
-
Save codeguy/6689266 to your computer and use it in GitHub Desktop.
Geocode address with Google Maps API
This file contains 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
/** | |
* Geocode address | |
* | |
* REQUIREMENTS | |
* - Google Maps API | |
* - HTML5 Geolocation API | |
*/ | |
var geocode = function (address, onSuccess, onError) { | |
var geocoder = new google.maps.Geocoder(); | |
geocoder.geocode({ address: address }, function (results, status) { | |
if (status === google.maps.GeocoderStatus.OK) { | |
console.log('Geocoded address', results); | |
var latlng = results[0].geometry.location; | |
onSuccess(latlng.lat(), latlng.lng()); | |
} else { | |
console.log('Geocoding address failed with error status', status); | |
onError(status); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment