GoogleMapSample9:地図にシンプルなラインを引く

地図の上にポリィラインと呼ばれる線を引く。公式サイトにあるサンプルです。
ポイントを増やせば複雑な線も引けるが、複雑な線はラインのエンコードを使った方が楽。

1
2
3
4
5
6
7
8
9
10
11
12
13
window.onload = function() {
   
  if (GBrowserIsCompatible()) {
    var map = new GMap(document.getElementById("map"));
     
    map.setCenter(new GLatLng(35.68358352238149,139.6933078765869), 14);
    var polyline = new GPolyline([
      new GLatLng(35.68958759004372,139.69174146652222),
      new GLatLng(35.676611614196176,139.69948768615723)
    ], "#ff0000", 10);
    map.addOverlay(polyline);
  }
}

map.setCenter(new GLatLng(35.68358352238149,139.6933078765869), 14);
地図の中心と拡大率を設定。pointとか変数使っても良い。

var polyline = new GPolyline([point],#color,size);
GPolylineオブジェクト作成。ポイント、色、太さです。
ポイントが複数ある場合は配列にする。

map.addOverlay(polyline);
マップにpolylineを追加する。

コメントを残す

This site uses Akismet to reduce spam. Learn how your comment data is processed.