【发布时间】: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