-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
154 lines (148 loc) · 4.9 KB
/
main.js
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
let directionsService, directionsDisplay;
let origin_latitude, origin_longitude;
let dest_latitude = 28.676216,
dest_longitude = 77.113671;
function initMap() {
directionsService = new google.maps.DirectionsService();
directionsDisplay = new google.maps.DirectionsRenderer();
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 20,
center: { lat: 28.675592899999998, lng: 77.1128999 }
});
directionsDisplay.setMap(map);
getLocation();
}
function getLocation(ele) {
if (ele !== undefined) {
switch (ele.id) {
case 'cr_yl':
navigator.geolocation.getCurrentPosition(showPosition);
break;
case 'cr_mg':
origin_latitude = 28.676216;
origin_longitude = 77.113671;
break;
case 'cr_con':
origin_latitude = 28.67613;
origin_longitude = 77.113283;
break;
case 'cr_c3':
origin_latitude = 28.6756676;
origin_longitude = 77.1130431;
break;
case 'cr_c5':
origin_latitude = 28.6756742;
origin_longitude = 77.1130449;
break;
case 'cr_hm':
origin_latitude = 28.6755776;
origin_longitude = 77.1131961;
break;
case 'cr_a7':
origin_latitude = 28.676103;
origin_longitude = 77.113272;
break;
case 'cr_ch':
origin_latitude = 28.67613;
origin_longitude = 77.113283;
break;
case 'cr_cl':
origin_latitude = 28.675851;
origin_longitude = 77.11303;
break;
case 'cr_au':
origin_latitude = 28.676745;
origin_longitude = 77.112626;
break;
case 'dt_mg':
dest_latitude = 28.676216;
dest_longitude = 77.113671;
break;
case 'dt_con':
dest_latitude = 28.67613;
dest_longitude = 77.113283;
break;
case 'dt_c3':
dest_latitude = 28.6756676;
dest_longitude = 77.1130431;
break;
case 'dt_c5':
dest_latitude = 28.6756742;
dest_longitude = 77.1130449;
break;
case 'dt_hm':
dest_latitude = 28.6755776;
dest_longitude = 77.1131961;
break;
case 'dt_a7':
dest_latitude = 28.676103;
dest_longitude = 77.113272;
break;
case 'dt_ch':
dest_latitude = 28.67613;
dest_longitude = 77.113283;
break;
case 'dt_cl':
dest_latitude = 28.675851;
dest_longitude = 77.11303;
break;
case 'dt_au':
dest_latitude = 28.676745;
dest_longitude = 77.112626;
break;
}
if(ele.id[0]==='c')
document.getElementById('startButton').innerHTML =`${$("#"+ele.id).text()} (A)`;
else if(ele.id[0]==='d')
document.getElementById('destButton').innerHTML =`${$("#"+ele.id).text()} (B)`;
showPosition();
} else if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = 'Geolocation is not supported by this browser.';
}
}
function showPosition(position) {
console.log('Hurray', position);
if (position !== undefined) {
origin_latitude = position.coords.latitude;
origin_longitude = position.coords.longitude;
dest_latitude = 28.676216;
dest_longitude = 77.113671;
console.log(
'Latitude: ' +
position.coords.latitude +
' Longitude: ' +
position.coords.longitude
);
}
calculateAndDisplayRoute();
}
function calculateAndDisplayRoute() {
directionsService.route(
{
origin: {
lat: origin_latitude,
lng: origin_longitude
},
destination: {
lat: dest_latitude,
lng: dest_longitude
},
travelMode: 'WALKING'
},
function(response, status) {
if (status === 'OK') {
directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
}
);
}
let openNavigation = () => {
window.open(
`http://maps.google.com/maps?saddr=${origin_latitude},${origin_longitude}&daddr=${dest_latitude},${dest_longitude} &travelmode=walking&dir_action=navigate`,
'_blank'
);
};