Try this
src="http://maps.googleapis.com/maps/api/js?sensor=true&libraries=geometry">
function calcRoute() {
geocoder = new google.maps.Geocoder();
var start = document.getElementById("start").value;
var end = document.getElementById("end").value;
var slatlng ;
var elatlng;
geocoder.geocode({ 'address': start }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var result = results[0].geometry.location.toString();
slatlng = results[0].geometry.location;
}
});
geocoder.geocode({ 'address': end }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var result = results[0].geometry.location.toString();
elatlng = results[0].geometry.location;
var distance = (google.maps.geometry.spherical.computeDistanceBetween(slatlng , elatlng ) / 1000).toFixed(2);
$('#distance').html("Distance between " +start+" and "+end+" is:"+distance);
}
});
}