I want the exact geographical distance between two address and it differs inthe Travelling mode in v3. please find the below code and the API file I called was script type='text/javascript' src='//maps.googleapis.com/maps/api/js?key=xxxxxxxxxxx'
function showLocation(a,b)
{
alert(a.value);
geocoder = new google.maps.Geocoder();
geocoder.geocode(document.forms[0].address.value, function (response) {
if (!response || response.Status.code != 200)
{
alert("Sorry, we were unable to geocode the first address");
}
else
{
location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
geocoder.getLocations(a.value, function (response) {
if (!response || response.Status.code != 200)
{
alert("Sorry, we were unable to geocode the second address");
}
else
{
location2= {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
var x=calculateDistance();
b.value = x;
}
});
}
});}
function calculateDistance(){
try
{
var glatlng1 = new GLatLng(location1.lat, location1.lon);
var glatlng2 = new GLatLng(location2.lat, location2.lon);
var miledistance = glatlng1.distanceFrom(glatlng2, 3959).toFixed(2);
return miledistance;
}
catch (error)
{
alert(error);
}}