変数 = Maps.newDirectionFinder();
《DirectionFinder》.setOrigin( 緯度 , 経度 );
《DirectionFinder》.setDestination(緯度 , 経度 );
変数 = 《DirectionFinder》.getDirections();
{
routes=[
{
bounds={
southwest={ 緯度 , 経度 },
northeast={ 緯度 , 経度 }
},
summary=サマリー,
copyrights=コピーライト,
waypoint_order=[],
legs=[
{
distance={text=距離, value=値},
duration={text=時間, value=値},
end_location={ 緯度 , 経度 },
start_address=住所,
end_address=住所,
start_location={ 緯度 , 経度 },
via_waypoint=[],
steps=[
{
distance={text=距離, value=値},
duration={text=時間, value=値},
html_instructions=説明テキスト,
end_location={lng=緯度, lat=経度},
polyline={points=配列},
start_location={lng=緯度, lat=経度},
travel_mode=モード
},
……必要なだけデータを記述……
],
},
……必要なだけデータが並ぶ……
]
}
],
status=ステータス
}
var path = Maps.decodePolyline(step.polyline.points);steps配列内のオブジェクトにはpolylineという値があり、そのpointsでパスのデータが得られます。
map.addPath(path);
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
function showDirection(){ // 2つの地名を入力 var getname1 = Browser.inputBox("地名", "1つ目の地名を入力:", Browser.Buttons.OK_CANCEL); var getname2 = Browser.inputBox("地名", "2つ目の地名を入力:", Browser.Buttons.OK_CANCEL); var map = Maps.newStaticMap().setSize(400, 300) .setLanguage('ja') .setMapType(Maps.StaticMap.Type.HYBRID); // Geoコーディングし位置を取得 var start = Maps.newGeocoder().setRegion("ja").setLanguage("ja").geocode(getname1); var end = Maps.newGeocoder().setRegion("ja").setLanguage("ja").geocode(getname2); var startpoint = start.results[0].geometry.location; var endtpoint = end.results[0].geometry.location; // DirectionFinderを作成 var directions = Maps.newDirectionFinder() .setOrigin(startpoint.lat,startpoint.lng) .setDestination(endtpoint.lat,endtpoint.lng) .getDirections(); // パスの設定をし、パスの描画を開始 map.setPathStyle(5, Maps.StaticMap.Color.GREEN, null); map.beginPath(); for (var i in directions.routes) { for (var j in directions.routes[i].legs) { for (var k in directions.routes[i].legs[j].steps) { var step = directions.routes[i].legs[j].steps[k]; var path = Maps.decodePolyline(step.polyline.points); map.addPath(path); } } } map.endPath(); // 2点のマーカーを表示 map.setMarkerStyle(Maps.StaticMap.MarkerSize.MID,Maps.StaticMap.Color.RED,"A"); map.addMarker(getname1); map.setMarkerStyle(Maps.StaticMap.MarkerSize.MID,Maps.StaticMap.Color.BLUE,"B"); map.addMarker(getname2); var sheet = SpreadsheetApp.getActiveSpreadsheet(); var url = map.getMapUrl(); sheet.getRange("a1").setValue(url); }
<< 前へ |