Skip to content

Instantly share code, notes, and snippets.

@AppMkrATL
Forked from codeguy/geocode-address.js
Created September 12, 2018 04:37
Show Gist options
  • Save AppMkrATL/0fb295b4b0221f69eda9e8d868f5c86c to your computer and use it in GitHub Desktop.
Save AppMkrATL/0fb295b4b0221f69eda9e8d868f5c86c 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