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

実行結果


【ピクセル座標】
X座標: Y座標:
X座標、Y座標をカンマ区切りの文字列として取得:

ソース

<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"));
        /* 中心地点 */
        var latlng=new GLatLng(35.665246,139.712319);
        map.setCenter(latlng, 14);
        /* ドラッグ可能な地図を含むDOM要素内で指定した地理的地点をピクセル座標に変換 */
        var obj=map.fromLatLngToDivPixel(latlng);
        document.getElementById("res_x").value=obj.x;    /* X座標 */
        document.getElementById("res_y").value=obj.y;    /* Y座標 */
        document.getElementById("res_xy").value=obj.toString();    /* XY座標を文字列として取得 */
    }
}
window.onload=load;
window.unload=GUnload;
//]]>
</script>
<div id="map" style="width:425px;height:300px"><!-- 地図描画領域 --></div><br>
<form action="#">
    【ピクセル座標】<br>
    X座標:<input type="text" size="10" id="res_x" /> Y座標:<input type="text" size="10" id="res_y" /><br>
    X座標、Y座標をカンマ区切りの文字列として取得:<input type="text" size="20" id="res_xy" />
</form>

polarized women