Currently, I am on the lookout for a minimalistic Google geocoding script. Most scripts I have come across are quite large and complex, but this one stands out for its simplicity. However, it lacks the feature of automatically inputting the coordinates into two separate input boxes like other scripts do.
You can view the working code here: http://jsfiddle.net/Rr5PL/89/
I'm wondering how I can modify it to populate the latitude and longitude in respective input fields. The script must already store these coordinates since it uses them to display the location on the map.
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
}
function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}