0

私はgoogledし、stackoverflowで深く検索しましたが、結果はありませんでした。

私は次のコードを持っています:

<script type="text/javascript">


    function initialize() {
        var map = new google.maps.Map(document.getElementById('map'), {
            zoom: 7,
            center: new google.maps.LatLng(45.47554, 9.204712),
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            disableDefaultUI: true,
            zoomControl: true
        });


    }
    google.maps.event.addDomListener(window, 'load', initialize);

    google.maps.event.addListener(map, "click", function (event) {
        alert("click");
    });

</script>

マップをクリックしても、アラートは表示されません。どこが間違っていますか?ありがとうございました。

4

1 に答える 1

0

あなたは言及no way to add a markerしましたが、この場合、マップにマーカーを追加するには、次のコードを使用できます

function initialize() {
    var map = new google.maps.Map(document.getElementById('map'), {
        // options
    });

    // Add a marker at center/current latlng
    var marker = new google.maps.Marker({
        position: map.getCenter(),
        map: map,
        title: 'Some Title'
    });

    // To add a click event on the marker you can use
    google.maps.event.addListener(marker, 'click', function() {
        // ...
    });
}

続きを読む。

于 2013-04-05T16:18:00.820 に答える