我们在触发Map事件时遇到问题...我们尝试了以下代码,但Map Pan事件只是第一次触发。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map-canvas { height: 100% }
</style>
<script charset="UTF-8" type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=<key>&sensor=false"></script>
<script type="text/javascript">
function initialize() {
var mouseDown;
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
map.addListener("center_changed", function() {
// alert("center_changed");
console.log("center_changed");
});
map.addListener("mouseup", function() {
this.mouseDown = false;
// alert("mouseup");
});
map.addListener("mousedown", function() {
this.mouseDown = true;
// alert("mousedown");
});
}
google.maps.event.addDomListener(window, 'load', initialize);
/* google.maps.event.addListener('dragend', function() {
return function() {
console.log("Drag Event Called");
}
});
*/
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
请提出克服这个想法的想法......
答案 0 :(得分:3)
而不是map.addListener
您应该尝试使用google.maps.event.addDomListener
:
google.maps.event.addDomListener(map, 'dragend', function () {
console.log('center changed');
});
答案 1 :(得分:3)
你可以试试这个。
map.addListener("dragend", function() {
// alert("center_changed");
count++;
console.log("center_changed"+count);
//ur method .....
});