-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_route.html
181 lines (161 loc) · 5.86 KB
/
plot_route.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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Waypoints in directions</title>
<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%;
float: left;
width: 70%;
height: 100%;
}
#right-panel {
margin: 20px;
border-width: 2px;
width: 20%;
float: left;
text-align: left;
padding-top: 20px;
}
#directions-panel {
margin-top: 20px;
background-color: #FFEE77;
padding: 10px;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="right-panel">
<div>
<b style="font-size:14pt">Safest Walking Route:</b>
<div id="inputs">
<br><br><label style="font-size:13pt">Origin:</label><input style="font-size:13pt" type="text" name="source" id="source"/>
<br><br><label style="font-size:13pt">Destination:</label><input style="font-size:13pt" type="text" name="dest" id="dest"/>
</div>
<br>
<i>**Waypoints: Stores open for 24 hours</i> <br>
<input type="submit" id="submit">
</div>
</div>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script><script>
function initMap() {
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 6,
center: {lat: 41.85, lng: -87.65}
});
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('right-panel'));
document.getElementById('submit').addEventListener('click', function() {
calculateAndDisplayRoute(directionsService, directionsDisplay);
});
}
function calculateAndDisplayRoute(directionsService, directionsDisplay) {
var geocoder = new google.maps.Geocoder();
var src = document.getElementById('source').value;
var dst = document.getElementById('dest').value;
geocoder.geocode( {'address': src}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var coord = [];
origin_lat = results[0].geometry.location.lat();
origin_lng = results[0].geometry.location.lng();
}
});
geocoder.geocode( {'address': dst}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var coord2 = [];
dest_lat = results[0].geometry.location.lat();
dest_lng = results[0].geometry.location.lng();
}
});
var lat = [];
var lon = [];
var WordFile = new XMLHttpRequest();
WordFile.open("GET","file:///home/bigdata/AdvBigData/Safe_Route_NYC/node_modules/xlsx-to-json/nyc/coord.txt",false);
WordFile.onreadystatechange =
function() {
if(WordFile.readyState === 4)
{
if(WordFile.status === 200 || WordFile.status == 0)
{
var lines = WordFile.responseText.split("\n");
for (var i=0;i<lines.length;i++) {
var latitude = {};
var longitude = {};
var attributes = lines[i].split(",");
latitude = attributes[0];
longitude = attributes[1];
lat.push(latitude);
lon.push(longitude);
}
}
}
};
WordFile.send(null);
var waypts = [];
for (var i = 1; i < lat.length - 2; i++) {
waypts.push({
location: {lat: Number(lat[i]), lng: Number(lon[i])},
stopover: true
});
}
// waypoints (middle values)
directionsService.route({
origin: document.getElementById('source').value,
destination: document.getElementById('dest').value,
// origin: {lat: Number(lat[0]), lng: Number(lon[0])},
// destination: {lat: Number(lat[lat.length - 2]), lng: Number(lon[lon.length - 2])},
waypoints: waypts,
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.WALKING
}, function(response, status) {
if (status === google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
// var route = response.routes[0];
// var summaryPanel = document.getElementById('directions-panel');
// summaryPanel.innerHTML = '';
// // For each route, display summary information.
// for (var i = 0; i < route.legs.length; i++) {
// var routeSegment = i + 1;
// summaryPanel.innerHTML += '<b>Route Segment: ' + routeSegment +
// '</b><br>';
// summaryPanel.innerHTML += route.legs[i].start_address + ' to ';
// summaryPanel.innerHTML += route.legs[i].end_address + '<br>';
// summaryPanel.innerHTML += route.legs[i].distance.text + '<br><br>';
// }
//document.getElementById("StartID").textContent = route.legs[0].start_address;
//document.getElementById("EndID").textContent = route.legs[route.legs.length-1].end_address;
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDZTIm1Wl5U12BD_VqnLXzVF2NY4zBzpd0&callback=initMap">
</script>
</body>
</html>