./topimag900x150

www.h2caster.net

Linux&LAMP PHP&MySQL GPS&PDA BikeTrial blog Others

GoogleMapAPIで遊ぶ(2)

ポリラインの描画

 var polyline = new GPolyline([
      new GLatLng(35.38004 , 137.51826),
      new GLatLng(35.38104 , 137.51926)
      ], "#ff0000", 5, 0.7);
 map.addOverlay(polyline);
  var points = [];
      points.push(new GLatLng(35.38004 , 137.51826));
      points.push(new GLatLng(35.38015 , 137.51837));
      points.push(new GLatLng(35.35115 , 137.51937));
      points.push(new GLatLng(35.36215 , 137.52037));
      points.push(new GLatLng(35.38015 , 137.51737));
 map.addOverlay(new GPolyline(points, "#00ffff", 5 , 0.8));

Internet Exproler への対応

 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">

は、後ろの xmlns:v="urn:schemas-microsoft-com:vml"の部分を追加。

 <style type="text/css">v?:* {behavior:url(#default#VML);}</style>

の1行を追加。ちなみに、全体は、

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example</title>
        <style type="text/css">v?:* {behavior:url(#default#VML);}</style>
 
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=*******************"
     type="text/javascript"></script>
    <script type="text/javascript">
 
    //<![CDATA[
 
    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(35.38004 , 137.51826), 15);
        map.addControl(new GLargeMapControl());
      
             var points = [];
                    points.push(new GLatLng(35.38004 , 137.51826)); 
                    points.push(new GLatLng(35.38015 , 137.51837));
                    points.push(new GLatLng(35.35115 , 137.51937));
                    points.push(new GLatLng(35.36215 , 137.52037));
                    points.push(new GLatLng(35.38015 , 137.51737));
               map.addOverlay(new GPolyline(points, "#00ffff", 5 , 0.8));
      }
    }
    //]]>
    </script>
  </head>
  <body onload="load()" onunload="GUnload()">
    <div id="map" style="width: 500px; height: 500px"></div>
  </body>
 </html>

これでポリラインが描ける。ちなみに、ポリライン関数GPolyLineの引数の二番目は色。三番目は太さ(ピクセル)、四番目は透明度(0〜1)である。

Copyrite 2005 caster productions

www.h2caster.net