【问题标题】:Add markers not working on google maps javascript添加标记不适用于谷歌地图javascript
【发布时间】:2015-05-24 19:41:16
【问题描述】:

我一直试图让地点标记功能正常工作,但每次我点击地图时,标记都不会出现。我尝试在函数中添加 console.log() 语句,当您单击地图并接受正确的参数时,程序确实进入了函数,但标记没有显示。如果有人可以帮助我感激它。

<html>
<head>
    <script src="http://maps.googleapis.com/maps/api/js"></script>
    <script>
        var map,
            myLatLng = new google.maps.LatLng(55.8617, -4.2417);
        function initialize() {
            var mapOptions = {
                center: myLatLng,
                zoom: 15
            },
            marker;

            var map = new google.maps.Map(document.getElementById("mapDiv"), mapOptions);

            placeMarker(myLatLng);

            google.maps.event.addListener(map, 'click', function(event) {
                placeMarker(event.latLng);
            });
        }

        function placeMarker(location) {
            marker = new google.maps.Marker({
                position: location,
                map: map
            });
        }
        google.maps.event.addDomListener(window, 'load', initialize);
    </script>
</head>

<body>
    <div id="mapDiv" style="width:500px;height:380px;"></div>
</body>
</html>

【问题讨论】:

    标签: javascript google-maps google-maps-api-3 google-maps-markers


    【解决方案1】:

    实际上想出了我自己问题的答案。两次声明 map 变量,实际上花了我一个多小时才注意到:(

    【讨论】:

      猜你喜欢
      • 2018-04-02
      • 1970-01-01
      • 2020-10-12
      • 1970-01-01
      • 1970-01-01
      • 2018-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多