-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-map.php
105 lines (101 loc) · 3.36 KB
/
generate-map.php
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
<?php
$loc=array();
foreach($_POST['key'] as $k=>$value){
$loc[$value]=$_POST['val'][$k];
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>CRFTW</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<div id="map"></div>
<div id="right-panel">
<div>
<b>Punct de plecare:</b>
<select id="start">
<?php foreach($loc as $k=>$value)
echo "<option value='$k'>$value</option>" ;
?>
</select>
<br>
<b>Directii:</b> <br>
<i>(Ctrl+Click or Cmd+Click for multiple selection)</i> <br>
<select multiple id="waypoints">
<?php foreach($loc as $k=>$value)
echo "<option value='$k'>$value</option>" ;
?>
</select>
<br>
<b>Sfarsit:</b>
<select id="end">
<?php foreach($loc as $k=>$value)
echo "<option value='$k'>$value</option>" ;
?>
</select>
<br>
<input type="submit" id="submit">
</div>
<div id="directions-panel"></div>
<a href="/" class="buton-acasa">Introdu alt text</a>
</div>
<script>
function initMap() {
var directionsService = new google.maps.DirectionsService;
var directionsRenderer = new google.maps.DirectionsRenderer;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 6,
center: {lat: 41.85, lng: -87.65}
});
directionsRenderer.setMap(map);
document.getElementById('submit').addEventListener('click', function() {
calculateAndDisplayRoute(directionsService, directionsRenderer);
});
}
function calculateAndDisplayRoute(directionsService, directionsRenderer) {
var waypts = [];
var checkboxArray = document.getElementById('waypoints');
for (var i = 0; i < checkboxArray.length; i++) {
if (checkboxArray.options[i].selected) {
waypts.push({
location: checkboxArray[i].value,
stopover: true
});
}
}
directionsService.route({
origin: document.getElementById('start').value,
destination: document.getElementById('end').value,
waypoints: waypts,
optimizeWaypoints: true,
travelMode: 'DRIVING'
}, function(response, status) {
if (status === 'OK') {
directionsRenderer.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>';
}
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDjBYP7p7uWUHBRQGibO4byXY2GNmUphjw&callback=initMap">
</script>
</body>
</html>