測地系の設定

+Sponsored Links

使用される測地系はデフォルトでは日本測地系ですが世界測地系を使用することもできます。地図の測地系を設定するにはYahooMapsCtrlクラスのコンストラクタで指定します。

YahooMapsCtrl(id, pos, layer, mode, datum)

5番目の引数に地図の種類を表す値を指定します。指定可能な値は次のいずれかの定数です。

YDatumType.TOKYO97  日本測地系
YDatumType.WGS84    世界測地系

デフォルトの値は「YDatumType.TOKYO97」となっています。世界測地系を使用する場合は「YDatumType.WGS84」を指定して下さい。

例えば次のように記述します。

var latlng = new YLLPoint("35.62376724,139.77786836");
var layer = 5;
var mode = YMapMode.AERO;
var datum = YDatumType.WGS84;
var mapsctrl = new YahooMapsCtrl("map", latlng, layer, mode, datum);

サンプルプログラム

それでは簡単なサンプルで試してみます。

sample2_1.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>Yahoo!地図APIテスト</title>
<style type="text/css">
#map{
  width: 400px;
  height: 200px;
}
</style>
<script type="text/javascript"
  src="http://map.yahooapis.jp/MapsService/js/V2/?appid=(ID)">
</script>
<script type="text/javascript" src="./js/script2_1.js">
</script>
</head>
<body>

<p>Yahoo!地図APIテスト</p>
<div id="map"></div>

<!-- Begin Yahoo! JAPAN Web Services Attribution Snippet -->
<a href="http://developer.yahoo.co.jp/about"><img src="http://i.yimg.jp/images/yjdn/yjdn_attbtn1_125_17.gif" title="Webサービス by Yahoo! JAPAN" alt="Web Services by Yahoo! JAPAN" width="125" height="17" border="0" style="margin:4px 0px 15px 0px"></a>
<!-- End Yahoo! JAPAN Web Services Attribution Snippet -->

<div style="margin:5px 0 0 0;"><img src="http://maps.google.com/staticmap?center=35.689509,139.691752&zoom=16&size=400x200&key=(key)" /></div>

</body>
</html>

script2_1.js

window.onload = initialize;

function initialize() {
  var latlng = new YLLPoint(35.689509,139.691752);
  var layer = 2;
  var mode = YMapMode.MAP;
  var datum = YDatumType.WGS84;
  var mapsctrl = new YahooMapsCtrl("map", latlng, layer, mode, datum);
}

上記を実際にブラウザ見てみると次のように表示されます。

測地系の設定

今度はどちらの測地系も世界測地系ですので、同じ緯度経度を指定すれば同じ地点を表示します。他の緯度経度を指定した場合の例も見てみます。

測地系の設定

今度の場合も同じ地点を表示します。