Vistual Earth Map Control 6.1, Reverse Geocoding

投稿日 : 2008年4月13日 0:16

 Virtual Earth Mao Control の MSDNライブラリの内容が Version 6.1 になりました。6.0からの変更点についても記述されています。

 新しい機能のひとつにReverse Geocodingがあります。これは経緯度から住所を導き出すというものです(今までは住所から経緯度を出すことはできました)。今のところ対応しているのはアメリカだけなのでほとんど役に立ちませんが。

 VEMapクラスにFindLocationsメソッドが追加されているので、これを使います。引数は経緯度を表すVELatLongオブジェクトとコールバック関数になります。Reverse Geocodingが成功した場合、コールバック関数にはVEPlaceオブジェクトの配列が返ってきます。JavaScript部分のコードはこんな感じ。

var map = null;
function pageLoaded() {
map = new VEMap('myMap');
map.LoadMap();

var latlong = new VELatLong(38.898685474220485, -77.0356341012553);
map.SetCenterAndZoom(latlong, 17);

map.FindLocations(latlong, 
    function(locations) {
        var msg = '';
        if (!locations) {
            msg = 'No result found.';
        } else {
            for (var i = 0; i < locations.length; ++i) {
                msg += locations[i].Name + "\n";
            }
        }
        alert(msg);
    });
}

 HTML部分は以下の感じ。

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1"></script>
<script type="text/javascript">
    // JavaScriptのコード
</script>
</head>
<body onload="pageLoaded();">
    <div id='myMap' style="position:relative; width:400px; height:400px;"></div>
</body>

 実行結果はこうなります。アメリカで最も有名な住所らしいですよ。

Reverse Geocoding

コメントの入力
タイトル
名前
Url
コメント