回答編集履歴
3
修正
test
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
```GAS
|
14
14
|
function myFunction() {
|
15
|
-
let jikan = new Date(2023,1,2
|
15
|
+
let jikan = new Date(2023,1,23);
|
16
16
|
let startpoint = '東京駅';
|
17
17
|
let endpoint = '東京タワー';
|
18
18
|
|
2
追記
test
CHANGED
@@ -9,3 +9,39 @@
|
|
9
9
|
.addPath(Maps.decodePolyline(nearestRoute.legs[0].steps[0].polyline.points))
|
10
10
|
```
|
11
11
|
これでダメなんですかね?
|
12
|
+
|
13
|
+
```GAS
|
14
|
+
function myFunction() {
|
15
|
+
let jikan = new Date(2023,1,22);
|
16
|
+
let startpoint = '東京駅';
|
17
|
+
let endpoint = '東京タワー';
|
18
|
+
|
19
|
+
var start = Maps.newGeocoder().geocode(startpoint)['results'][0]['geometry']['location']['lat']+","+Maps.newGeocoder().geocode(startpoint)['results'][0]['geometry']['location']['lng']
|
20
|
+
var end = Maps.newGeocoder().geocode(endpoint)['results'][0]['geometry']['location']['lat']+","+Maps.newGeocoder().geocode(endpoint)['results'][0]['geometry']['location']['lng']
|
21
|
+
|
22
|
+
var directionFinder = Maps
|
23
|
+
.newDirectionFinder()
|
24
|
+
.setAlternatives(true) // ベストパスだけではなく、代替経路も出力する
|
25
|
+
.setLanguage('ja') // 日本語設定
|
26
|
+
.setOrigin(start) // start変数を始点に設定
|
27
|
+
.setDestination(end) // end変数を終点に設定
|
28
|
+
.setMode(Maps.DirectionFinder.Mode.DRIVING) // 自動車利用に設定。他、DRIVINGをWALKINGに変更で徒歩になる。
|
29
|
+
.setDepart(jikan) // jikan変数を出発時刻に設定
|
30
|
+
.getDirections().routes;
|
31
|
+
|
32
|
+
const nearestRoute = directionFinder.sort((a,b)=> a.legs[0].distance.value - b.legs[0].distance.value)[0]
|
33
|
+
|
34
|
+
let map = new Maps.newStaticMap()
|
35
|
+
map.setSize(400 , 300)
|
36
|
+
.setLanguage('ja')
|
37
|
+
.setPathStyle(3, Maps.StaticMap.Color.Blue , null) // 幅、線の色、塗りつぶしの色
|
38
|
+
.addPath(Maps.decodePolyline(nearestRoute.legs[0].steps[0].polyline.points))
|
39
|
+
|
40
|
+
}
|
41
|
+
|
42
|
+
```
|
43
|
+
上記コードで試しましたが、jikanが古いとルートが取得できずにdirectionFinderが空っぽでした。
|
44
|
+
現在から1か月以内であればルートが取得できるようです。
|
45
|
+
|
46
|
+
提示コードですと去年の12月固定になっているのでルートが取得できずにエラーが出たのではないでしょうか?
|
47
|
+
とりあえず`jikan = new Date()`と本日でやってみてはどうでしょうか。
|
1
修正
test
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
-
nearestRouteは配列なのではないでしょうか?
|
1
|
+
~~nearestRouteは配列なのではないでしょうか?~~
|
2
2
|
```GAS
|
3
3
|
.addPath(Maps.decodePolyline(nearestRoute[0].legs[0].steps[0].polyline.points))
|
4
4
|
```
|
5
|
-
こういうことだったりしませんか?
|
5
|
+
~~こういうことだったりしませんか?~~
|
6
|
+
|
7
|
+
すみません。勘違いです。
|
8
|
+
```GAS
|
9
|
+
.addPath(Maps.decodePolyline(nearestRoute.legs[0].steps[0].polyline.points))
|
10
|
+
```
|
11
|
+
これでダメなんですかね?
|