0 / 0 / 0
Регистрация: 21.05.2013
Сообщений: 3
|
|
1
|
Google Maps Api и Матрица маршрутов
21.05.2013, 21:56. Показов 1435. Ответов 0
у меня есть вот такой код, который выводит расстояние и время между любыми точками мира. Также там есть маркеры, которые делят расстояние на 10 участков. Мне надо найти время до каждого маркера с помощью еще одного запроса. Но вот как это сделать я не знаю. Прошу помощи. Вот код. HTML5 | 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
| <!DOCTYPE html>
<html>
<head>
<title>Distance Matrix service</title>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<meta charset="utf-8">
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map-canvas {
height: 100%;
width: 50%;
}
#content-pane {
float:right;
width:48%;
padding-left: 2%;
}
#outputDiv {
font-size: 11px;
}
</style>
<script>
var map;
var geocoder;
var bounds = new google.maps.LatLngBounds();
var markersArray = [];
var waypts = [];
var destinationIcon = 'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=D|FF0000|000000';
var originIcon = 'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=O|FFFF00|000000';
var directionsDisplay;
var directionsDisplay1;
var directionsService = new google.maps.DirectionsService();
var directionsService1 = new google.maps.DirectionsService();
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var opts = {
center: new google.maps.LatLng(55.53, 9.4),
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'), opts);
directionsDisplay.setMap(map);
geocoder = new google.maps.Geocoder();
}
function calcRoute() {
var start = document.getElementById('start').value;
var end = document.getElementById('end').value;
var request = {
origin: start,
destination: end,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
var route = response.routes[0];
var summaryPanel = document.getElementById('directions_panel');
var f;
var f1;
summaryPanel.innerHTML = '';
// For each route, display summary information.
for (var i = 0; i < route.legs.length; i++) {
f=(route.legs[i].end_location.lat()-route.legs[i].start_location.lat())/10 ;
f1=(route.legs[i].end_location.lng()-route.legs[i].start_location.lng())/10;
summaryPanel.innerHTML +=' Координаты начала '+ route.legs[i].start_location + ' среднее ';
summaryPanel.innerHTML += f + '<br>';
summaryPanel.innerHTML += f1 + '<br>';
summaryPanel.innerHTML += 'Время:'+route.legs[i].duration.text + '<br><br>';
var markers = [];
for(var k=1; k<=9; ++k)
markers[k-1] = new google.maps.Marker({
position: new google.maps.LatLng(route.legs[i].start_location.lat()+f*k, route.legs[i].start_location.lng()+f1*k),
icon: destinationIcon,
map: map
});
}
}
});
}
}
}
});
}
function deleteOverlays() {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(null);
}
markers = [];
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="content-pane">
<style>
.outputDiv
{
font-size:35px;
}
</style>
<div id="directions_panel" style="margin:20px;background-color:#FFEE77;"></div>
<div id="directions_panel1" style="margin:20px;background-color:#FFEE77;"></div>
<input type="text" name="start" id="start" >
<input type="text" name="end" id="end" >
<div id="outputDiv"></div>
<input type="submit" onclick="calcRoute();">
<input type="submit" onclick="calcRoute1();">
</div>
<div id="map-canvas"></div>
</body>
</html> |
|
0
|