Skip to content

Instantly share code, notes, and snippets.

@davidchase
Created April 10, 2013 12:33
Show Gist options
  • Save davidchase/5354220 to your computer and use it in GitHub Desktop.
Save davidchase/5354220 to your computer and use it in GitHub Desktop.
google maps from address to latlng

Geocoder

The function converts an address that a user enters to geocode aka lat/lng.

The results stored in a variable to later use in a application sense.

geocoder = new google.maps.Geocoder();
function encodeAddress() {
//get value from input
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
// lat and longitude stored in variable encoded
var encoded = results[0].geometry.location;
} else {
// log the results incase it didnt work and show why..
console.log("Geocode was not successful for the following reason: " + status);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment