Reading Address From Form And Outputting Longitude & Latitude
I'm quite new to JavaScript and am currently playing around with it and practicing trying to get a Google-geocoder function to print out the longitude and latitude in text fields.
Solution 1:
can you try this and tell me what is the result so that i can help you....
function codeAddress()
{
var geocoder = new google.maps.Geocoder();
var address = document.getElementById("address").value;
alert("address : "+address);// should display text you entered in input field
geocoder.geocode( {'address': address}, function(results, status) {
if(status == google.maps.GeocoderStatus.OK)
{
alert("entered if statement");// you have entered if statement
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
alert("latitude : "+latitude+" : longitude : "+longitude);// display values of latitude and longitude.
document.getElementById("latitude").value = latitude;
document.getElementById("longitude").value = longitude;
}
else
{
alert("Geocode was not successful for the following reason: " + status);
}
});
}
if you get all alert message except the last one with correct values and still not able to set the values in input field try this...
document.getElementById("latitude").innerHTML = latitude;
document.getElementById("longitude").innerHTML = longitude;
Post a Comment for "Reading Address From Form And Outputting Longitude & Latitude"