PHP & JavaScript Room :: 設置サンプル

実行結果


【地図の表示範囲の地理座標】

ソース

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAvABrzCnRluKK0Cj97fTMThTNR7aHVSEFb0WbViWwc6F-_w9PjBSogZu_7UgOTbx25ka46X-fnGmyvw" 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.665246,139.712319), 14);
        /* ★地図の表示範囲の地理地点を取得 */
        var bounds=map.getBounds();
        var sw=bounds.getSouthWest();
        var ne=bounds.getNorthEast();
        /* ★地図の表示範囲の地理地点を取得 */
        var s="";
        s+="左下の緯度:"+sw.lat()+"\n左下の緯度:"+sw.lng()+"\n\n";
        s+="右上の緯度:"+ne.lat()+"\n右上の緯度:"+ne.lng()+"\n\n";
            s+="文字列として取得:"+bounds.toString();
        document.getElementById("res").value=s;

        /* 地図を動かした時 */
        GEvent.addListener(map, "moveend", function(){
            bounds=map.getBounds();
            sw=bounds.getSouthWest();
            ne=bounds.getNorthEast();
            /* ★地図の表示範囲の地理地点を取得 */
            s+="左下の緯度:"+sw.lat()+"\n左下の緯度:"+sw.lng()+"\n\n";
            s+="右上の緯度:"+ne.lat()+"\n右上の緯度:"+ne.lng()+"\n\n";
            s+="文字列として取得:"+bounds.toString();
            document.getElementById("res").value=s;
        });
    }
}
window.onload=load;
window.unload=GUnload;
//]]>
</script>
<div id="map" style="width:425px;height:300px"><!-- 地図描画領域 --></div><br>
<form action="#">
    【地図の表示範囲の地理座標】<br>
    <textarea cols="64" rows="7" id="res"></textarea>
</form>

polarized women