var map, origin, destination, directionsService, directionsDisplay;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: { lat: 34.0522, lng: -118.2437 },
zoom: 10
});
directionsService = new google.maps.DirectionsService();
directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(map);
}
function calculateDistanceTime() {
origin = document.getElementById('origin').value;
destination = document.getElementById('destination').value;
if (origin === " || destination === ") {
alert('Please enter both origin and destination');
return;
}\n\n var request = {\n origin: origin,\n destination: destination,\n travelMode: google.maps.TravelMode.DRIVING\n };\n\n directionsService.route(request, function (response, status) {\n if (status === google.maps.DirectionsStatus.OK) {\n directionsDisplay.setDirections(response);\n var route = response.routes[0];\n var leg = route.legs[0];\n document.getElementById('distance').innerText = leg.distance.text;\n document.getElementById('duration').innerText = leg.duration.text;\n document.getElementById('start_address').innerText = leg.start_address;\n document.getElementById('end_address').innerText = leg.end_address;\n } else {\n alert('Directions request failed due to ' + status);\n }\n });\n}\n\n
\n
Google Maps Distance Time Calculator
\n
Calculate distance and travel time between two locations using Google Maps.
\n
\n \n \n
\n
\n \n \n
\n
\n
\n
Results
\n
Distance:
\n
Estimated Travel Time:
\n
From:
\n
To:
\n
\n
\n
\n\n\n\n
\n
Google Maps Distance Time Calculator
\n
Calculate distance and travel time between two locations using Google Maps.
\n
\n \n \n
\n
\n \n \n
\n
\n
\n
Results
\n
Distance:
\n
Estimated Travel Time:
\n
From:
\n
To:
\n
\n
\n
\n\n\n\n
\n
Google Maps Distance Time Calculator
\n
Calculate distance and travel time between two locations using Google Maps.
\n
\n \n \n
\n
\n \n \n
\n
\n
\n
Results
\n
Distance:
\n
Estimated Travel Time:
\n
From:
\n
To:
\n
\n