forked from divyamamgai/Naveta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDistance1.html
83 lines (80 loc) · 2.31 KB
/
Distance1.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<html>
<head>
<title>Distance Matrix service</title>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDo2zIgcjZFtaxiY-JxtschUxRJfBhYKLY"></script>
<style>
#right-panel {
font-family: 'Roboto','sans-serif';
line-height: 30px;
padding-left: 10px;
}
#right-panel select, #right-panel input {
font-size: 15px;
}
#right-panel select {
width: 100%;
}
#right-panel i {
font-size: 12px;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
width: 50%;
}
#right-panel {
float: right;
width: 48%;
padding-left: 2%;
}
#output {
font-size: 11px;
}
</style>
</head>
<body>
<div id="right-panel">
<div id="output"></div>
</div>
<div id="map"></div>
<script>
var Source = 'USA';
var Destination = 'Ambala,India';
function initMap(Src,Dst) {
var Source = Src;
var Destination = Dst;
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) {
alert('Error was: ' + status);
} else {
var originList = response.originAddresses;
var destinationList = response.destinationAddresses;
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = '';
var results = response.rows[0].elements;
if(isNaN(results[0].distance) == 0)
{
alert(originList[0] + ' to ' + destinationList[0] + ': ' + results[0].distance.text);
} else {
alert("The Route is not possible by Driving.")
}
}
});
}
initMap(Source,Destination);
</script>
</body>
</html>