Javascript 谷歌地图v3-科尔多瓦-地图中心不会在拖动时更改
在拖动过程中,我试图在地图中心保留一个标记。我尝试使用拖动事件,但没有效果。 我还启动了一个setInterval例程来打印中心,在拖动过程中它没有改变。我做错什么了吗?有没有其他方法可以让标记保持在中间 这是我的事件侦听器Javascript 谷歌地图v3-科尔多瓦-地图中心不会在拖动时更改,javascript,google-maps,cordova,Javascript,Google Maps,Cordova,在拖动过程中,我试图在地图中心保留一个标记。我尝试使用拖动事件,但没有效果。 我还启动了一个setInterval例程来打印中心,在拖动过程中它没有改变。我做错什么了吗?有没有其他方法可以让标记保持在中间 这是我的事件侦听器 google.maps.event.addListener(MapPage.map,'center_changed', function() { if (MapPage.el.find('.selectedMenu').hasClass("rdv")){
google.maps.event.addListener(MapPage.map,'center_changed', function() {
if (MapPage.el.find('.selectedMenu').hasClass("rdv")){
var center = MapPage.map.getCenter();
MapPage.rdvMarker.setPosition(center);
//setInterval(function(){google.maps.event.trigger(map, 'dragend');console.log(MapPage.map.getCenter())},200);
}
});
您可以通过始终将标记设置在地图的中心来实现这一点!因此,无论何时拖动,它都会将标记置于地图的中心
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Hello World!'
});
google.maps.event.addListener(map, 'center_changed', function () {
// 0.1 seconds after the center of the map has changed,
// set back the marker position.
window.setTimeout(function () {
var center = map.getCenter();
marker.setPosition(center);
}, 1);
});
你是说中间的标记将保持不变,不会随着拖动而移动?是的,这正是我的意思