-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester.html
42 lines (39 loc) · 1.77 KB
/
tester.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html>
<head>
<title>Distance Calculation</title>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD10_lyiuqCuFpYvFoU6yhNz7wEEsG0b6s&callback=initMap"></script>
<script>
// Initialize Google Maps API
function initMap() {
// Create a new instance of DirectionsService
var directionsService = new google.maps.DistanceMatrixService();
// Define coordinates
var origin = new google.maps.LatLng(40.712776, -74.005974); // Example: New York City
var destination = new google.maps.LatLng(34.052235, -118.243683); // Example: Los Angeles
// Define request object
var request = {
origins: [origin],
destinations: [destination],
travelMode: google.maps.TravelMode.DRIVING, // You can change the travel mode as needed
unitSystem: google.maps.UnitSystem.METRIC // You can change the unit system as needed
};
// Call the distance matrix service
directionsService.getDistanceMatrix(request, function(response, status) {
if (status == google.maps.DistanceMatrixStatus.OK) {
var distance = response.rows[0].elements[0].distance.text;
var duration = response.rows[0].elements[0].duration.text;
console.log("Distance: " + distance);
console.log("Duration: " + duration);
} else {
console.log("Error: " + status);
}
});
}
</script>
</head>
<body>
<!-- This is just a placeholder for Google Maps to load -->
<div id="map" style="display: none;"></div>
</body>
</html>