终于取得了一些成功(地图仍然移动了一点,但目前可以忽略)!
声明了两个变量:
var isAnyMarkerIsInDraggingState = false;// if a marker is in drag state this value will be TRUE otherwise FALSE
var mapCenterPositionAtTheTimeWhenMarkerWasDragged;// Map Center Position
拖动标记时:
google.maps.event.addListener(objMarker, 'dragstart', function () {
// Store map center position when a marker is dragged
mapCenterPositionAtTheTimeWhenMarkerWasDragged = mapObject.getCenter();
isAnyMarkerIsInDraggingState = true;
});
放下标记时(拖动结束):
google.maps.event.addListener(objMarker, 'dragend', function () {
// Make Map draggable
// Set isAnyMarkerIsInDraggingState = false. Because no marker is in drag state
mapObject.setOptions({ draggable: true });
isAnyMarkerIsInDraggingState = false;
});
当地图拖动开始时:
google.maps.event.addListener(mapObject, 'dragstart', function () {
// isAnyMarkerIsInDraggingState = true: means the user is dragging a marker.
// If the user is dragging the Marker then don't allow the Map to be Dragged
if (isAnyMarkerIsInDraggingState) {
mapObject.setOptions({ draggable: false });
}
});
地图处于拖动状态时:
google.maps.event.addListener(mapObject, 'drag', function () {
// isAnyMarkerIsInDraggingState = true: means the user is dragging a marker.
// If the user is dragging the Marker then don't allow the Map to be Dragged and set its CenterPosition
// to mapCenterPositionAtTheTimeWhenMarkerWasDragged
if (isAnyMarkerIsInDraggingState) {
mapObject.setCenter(mapCenterPositionAtTheTimeWhenMarkerWasDragged);
}
});
完整的示例代码在这里。