-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuffer
73 lines (52 loc) · 2.15 KB
/
buffer
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
<script type="text/javascript">
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var latlngs = <?= json_encode($lat_lng); ?>;
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var myOptions = {
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
map = new google.maps.Map($("#map_canvas")[0], myOptions);
directionsDisplay.setMap(map);
plot_points(latlngs);
};
$(window).load(initialize);
// latlngs = [ new google.maps.LatLng(40.749537, -73.9879906), new google.maps.LatLng(40.758883, -73.981014), new google.maps.LatLng(40.7618193, -73.9791976), new google.maps.LatLng(40.761628, -73.968478) ];
// latlngs = [ new google.maps.LatLng(40.487978, -74.439342), new google.maps.LatLng(40.487978, -74.439342), new google.maps.LatLng(40.498187, -74.445195), new google.maps.LatLng(40.5041, -74.449091), new google.maps.LatLng(40.523768, -74.458305), new google.maps.LatLng(40.51992, -74.433583), new google.maps.LatLng(40.533959, -74.436622), new google.maps.LatLng(40.485633, -74.437406), new google.maps.LatLng(40.499666, -74.445021), new google.maps.LatLng(40.502681, -74.451444)
// ];
function plot_points(latlngs)
{
for(var i=0; i < latlngs.length; i++)
{
latlngs = new google.maps.LatLng(latlngs[i].lat, latlngs[i].lng);
}
latlngs_start = latlngs[0];
latlngs_end = latlngs[latlngs.length-1];
var waypts = [];
for (var i = 1 ; i < latlngs.length -1 ; i++ ) {
waypts.push({
location:latlngs[i],
stopover:true
});
}
console.log(waypts);
var request = {
origin: latlngs_start,
destination: latlngs_end,
waypoints: waypts,
optimizeWaypoints: false,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
console.log(response);
directionsDisplay.setDirections(response);
}
});
event.preventDefault();
return false;
};
</script>