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); | |
| } | |
| }); | |
| } |