-
-
Save AppMkrATL/0fb295b4b0221f69eda9e8d868f5c86c 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