添加不适用于google maps javascript的标记

添加不适用于google maps javascript的标记,javascript,google-maps,google-maps-api-3,google-maps-markers,Javascript,Google Maps,Google Maps Api 3,Google Maps Markers,我一直在努力让地点标记功能发挥作用,但每次我点击地图时,标记都不会出现。我尝试在函数中添加console.log()语句,当您单击映射并输入正确的参数时,程序确实会进入函数,但标记没有显示出来。如果有人能帮忙,我将不胜感激 <html> <head> <script src="http://maps.googleapis.com/maps/api/js"></script> <script> var ma

我一直在努力让地点标记功能发挥作用,但每次我点击地图时,标记都不会出现。我尝试在函数中添加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>

var映射,
myLatLng=new google.maps.LatLng(55.8617,-4.2417);
函数初始化(){
变量映射选项={
中心:myLatLng,
缩放:15
},
标记;
var map=new google.maps.map(document.getElementById(“mapDiv”)、mapOptions);
placeMarker(myLatLng);
google.maps.event.addListener(映射,'click',函数(事件){
地点标记(事件标记);
});
}
功能位置标记(位置){
marker=新的google.maps.marker({
位置:位置,,
地图:地图
});
}
google.maps.event.addDomListener(窗口“加载”,初始化);

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