0

我在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 回答