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[
var map, cEvent;
function load() {
    if(GBrowserIsCompatible()){
        /* 地図インスタンス生成 */
        map=new GMap2(document.getElementById("map"));
        /* 中心地点 */
        map.setCenter(new GLatLng(35.665246,139.712319), 14);
        /* マーカー追加 */
        marker=new GMarker(map.getCenter());
        map.addOverlay(marker);
        
         document.getElementById("res").value="";
       /* 地図にイベントを結び付ける */
        GEvent.bind(map, "click", this, fGetPoint);
        /* マーカーにイベントを結び付ける */
        GEvent.bind(marker, "click", this, fGetPoint);
    }
}
function fGetPoint(makerObj){
    /* イベント登録 */
    if(makerObj){
        document.getElementById("res").value="マーカーがクリックされました\nクリックされた地点の地理座標:"+makerObj;
    }else{
        document.getElementById("res").value="地図がクリックされました";
    }
}
window.onload=load;
window.unload=GUnload;
//]]>
</script>
<div id="map" style="width:425px;height:300px"><!-- 地図描画領域 --></div><br>
<form action="#">
    <p>
        <textarea cols="64" rows="2" id="res" style="width:421px;"></textarea>
    </p>
</form>

polarized women