mapsの Polyline(polyLineOptions) を利用します。
手順としては
-
線を引きたい座標を用意する
LatLng(35.701139, 139.797949) -
線を引くための各種情報をセットする
var polyLineOptions = {} -
線を引く
var poly = new google.maps.Polyline(polyLineOptions);
poly.setMap(map);
以上3ステップ。
ちなみに今回は複数地点の座標を既に設定していたため、
線を引く際に設定が必要なpathのために再度配列化しています。
(代入するのは配列でないといけないみたいです)
// 複数地点の座標
var map_data = new Array();
map_data.push({position: new google.maps.LatLng(35.701139, 139.797949), place:'東京' });
map_data.push({position: new google.maps.LatLng(10.384458,123.798679), place:'フィリピン' });
map_data.push({position: new google.maps.LatLng(60.173468, 24.941046), place:'フィンランド' });
map_data.push({position: new google.maps.LatLng(-10.688480, -75.968200), place:'ペルー' });
map_data.push({position: new google.maps.LatLng(39.625702, -100.213340), place:'アメリカ' });
// ラインの道筋(path)を指定するために配列を作成
// 以前のmap_dataに入れたオブジェクトを利用
var points = new Array();
for (i =0; i < map_data.length; i++) {
points.push(map_data[i].position);
}
function initialize() {
var mapOptions = {
zoom: 2,
center: map_data[0].position,
};
map = new google.maps.Map(document.getElementById('gt_map'),mapOptions);
for (i =0; i < map_data.length; i++) {
var marker = new google.maps.Marker({
position: map_data[i].position,
map: map,
icon: {
url: "icon.png",
// scalesizeでアイコンのサイズを設定
scaledSize: new google.maps.Size(10,10)
}
});
}
// /for
// ライン情報を設定
var polyLineOptions = {
path: points,
strokeWeight: 1,
strokeColor: "#0000ff",
strokeOpacity: "0.5"
};
// ラインを出力
var poly = new google.maps.Polyline(polyLineOptions);
poly.setMap(map);
}
// /initialize
google.maps.event.addDomListener(window, 'load', initialize);