Skip to content

Instantly share code, notes, and snippets.

@codeguy
Created September 24, 2013 18:37
Show Gist options
  • Save codeguy/6689266 to your computer and use it in GitHub Desktop.
Save codeguy/6689266 to your computer and use it in GitHub Desktop.
Geocode address with Google Maps API
/**
* 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