2011年9月29日木曜日

外部APIを利用したWEBサービスのサンプル(5)

Google Mapsのオーバーレイ機能を利用して,以下の要件を満たすHTMLファイルを作成せよ.

参考サイト
Google Maps JavaScript API V3 オーバーレイ

要件
1. 地図上の学校の場所に,アイコンを表示 → マーカー
2. アイコンをクリックした際に吹き出しを表示し,吹き出し内に学校名と電話番号を表示 → 情報ウィンドウ
3. 駅から学校までの通学路を線として表示 → ポリライン
表示例

LINK

overlays.html
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Marker Simple</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
  function initialize() {
    var myLatlng = new google.maps.LatLng(35.4649755,139.6162225);
    var mySchool = new google.maps.LatLng(35.463763,139.60973);
    var myStation = new google.maps.LatLng(35.466188, 139.622715);

    var myOptions = {
      zoom: 15,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var marker = new google.maps.Marker({
      position: mySchool,
      map: map,
      title:"school"
    });

  var route = [
    new google.maps.LatLng(35.466188, 139.622715),
    new google.maps.LatLng(35.463458,139.615631),
    new google.maps.LatLng(35.465424,139.612021),
    new google.maps.LatLng(35.463283,139.610087),
    new google.maps.LatLng(35.463763,139.60973)
  ];

  var routePath = new google.maps.Polyline({
    path: route,
    strokeColor: "#FF0000",
    strokeOpacity: 1.0,
    strokeWeight: 2
  });

  routePath.setMap(map);

  }
</script>
</head>
<body onload="initialize()">
  <div id="map_canvas"></div>
</body>
</html>

0 件のコメント: