I’m not sure why the following doesn’t work. It doesn’t enter the geocoder.geocode segment at all. All i want is to be able to receive a geocode for an address i enter without plotting it on any map.
var geocoder;
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
alert(results[0].geometry.location);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
html code:
<div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div>
Didn’t initialize geocoder. geocoder = new google.maps.Geocoder();