質問編集履歴
1
テストコードを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -65,3 +65,97 @@
|
|
65
65
|
|
66
66
|
|
67
67
|
どなたか詳しくご教示頂ければ幸甚で御座います。
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
###テストコード
|
72
|
+
|
73
|
+
```javascript
|
74
|
+
|
75
|
+
function calcRoute(startLatLng,targetLatLng){
|
76
|
+
|
77
|
+
var request = {
|
78
|
+
|
79
|
+
origin: new google.maps.LatLng(startLatLng[0], startLatLng[1]), // スタート地点
|
80
|
+
|
81
|
+
destination: new google.maps.LatLng(targetLatLng[0], targetLatLng[1]), // ゴール地点
|
82
|
+
|
83
|
+
travelMode: google.maps.DirectionsTravelMode.WALKING // 移動手段
|
84
|
+
|
85
|
+
};
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
directionsService.route(request, function (response, status) {
|
90
|
+
|
91
|
+
if(directionsDisplay){
|
92
|
+
|
93
|
+
directionsDisplay.setMap(null);
|
94
|
+
|
95
|
+
directionsDisplay.setPanel(null);
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
if (status === google.maps.DirectionsStatus.OK) {
|
102
|
+
|
103
|
+
var rendererOptions = {
|
104
|
+
|
105
|
+
map: map, // 描画先の地図
|
106
|
+
|
107
|
+
draggable: true, // ドラッグ可
|
108
|
+
|
109
|
+
//preserveViewport: true // centerの座標、ズームレベルで表示
|
110
|
+
|
111
|
+
suppressMarkers: true // デフォルトのマーカーを削除
|
112
|
+
|
113
|
+
};
|
114
|
+
|
115
|
+
directionsDisplay = new google.maps.DirectionsRenderer( rendererOptions );
|
116
|
+
|
117
|
+
directionsDisplay.setDirections( response );
|
118
|
+
|
119
|
+
directionsDisplay.setMap(map);
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
/*ルートの詳細表示*/
|
124
|
+
|
125
|
+
directionsDisplay.setPanel(document.getElementById("directions_panel"));
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
/* 出発地点・到着地点マーカーが移動された時 */
|
130
|
+
|
131
|
+
google.maps.event.addListener(directionsDisplay, 'directions_changed',function() {
|
132
|
+
|
133
|
+
currentDirections=directionsDisplay.getDirections();
|
134
|
+
|
135
|
+
var route=currentDirections.routes[0];
|
136
|
+
|
137
|
+
var s="";
|
138
|
+
|
139
|
+
for(var i=0; i<route.legs.length; i++) {
|
140
|
+
|
141
|
+
var routeSegment=i+1;
|
142
|
+
|
143
|
+
s+=route.legs[i].start_address+'to';
|
144
|
+
|
145
|
+
s+=route.legs[i].end_address+'\n';
|
146
|
+
|
147
|
+
s+=route.legs[i].distance.text;
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
dbg("directions_changed:"+s);
|
152
|
+
|
153
|
+
});
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
});
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
```
|