我们在触发 map 事件时遇到问题...我们尝试了以下代码,但 map 平移事件仅在第一次被触发。
<!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>
请提供克服这个问题的想法...
最佳答案
你可以试试这个。
map.addListener("dragend", function() {
// alert("center_changed");
count++;
console.log("center_changed"+count);
//ur method .....
});
关于javascript - 谷歌地图 V3 : Trigger map pan Event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20995963/