google map

Different between two coordinate’s Latitude and Longitude and show Google Maps and Distance?

Description –:  I take two label and two textbox and one button. Than after that create table and create 

Function  markerPoints and take a variable new google.maps.LatLng(lat[0], lon[0]),

Different between latitude and longitude   

and create another function DirectionsService()and get directions 

after that GetRoute()  and hear tak  latitude and longitude  value.

After that create function  DISTANCE AND DURATION 

var service = new google.maps.DistanceMatrixService();

google.maps.event.addDomListener(window, ‘load’, function () {

    new google.maps.places.SearchBox(document.getElementById(‘txtSource’));

    new google.maps.places.SearchBox(document.getElementById(‘txtDestination’));

    directionsDisplay = new google.maps.DirectionsRenderer({ ‘draggable’: true });

});

function GetRoute() {

    var mumbai = new google.maps.LatLng(18.9750, 72.8258);

    var mapOptions = {

        zoom: 7,

        center: mumbai

    };

    map = new google.maps.Map(document.getElementById(‘dvMap’), mapOptions);

    directionsDisplay.setMap(map);

    directionsDisplay.setPanel(document.getElementById(‘dvPanel’));

    //*********DIRECTIONS AND ROUTE**********************//

    source = document.getElementById(“txtSource”).value;

    destination = document.getElementById(“txtDestination”).value;

    var request = {

        origin: source,

        destination: destination,

        travelMode: google.maps.TravelMode.DRIVING

    };

    directionsService.route(request, function (response, status) {

        if (status == google.maps.DirectionsStatus.OK) {

            directionsDisplay.setDirections(response);

        }

    });

    //*********DISTANCE AND DURATION**********************//

    var service = new google.maps.DistanceMatrixService();

    service.getDistanceMatrix({

        origins: [source],

        destinations: [destination],

        travelMode: google.maps.TravelMode.DRIVING,

        unitSystem: google.maps.UnitSystem.METRIC,

        avoidHighways: false,

        avoidTolls: false

    }, function (response, status) {

        if (status == google.maps.DistanceMatrixStatus.OK && response.rows[0].elements[0].status != “ZERO_RESULTS”) {

            var distance = response.rows[0].elements[0].distance.text;

            var duration = response.rows[0].elements[0].duration.text;

            var dvDistance = document.getElementById(“dvDistance”);

           dvDistance.innerHTML = “”;

            dvDistance.innerHTML += “Distance: ” + distance + “<br />”;

            dvDistance.innerHTML += “Duration:” + duration;

        } else {

            alert(“Unable to find the distance via road.”);

        }

    });

}

</script>