【问题标题】:Internet Explorer + Windows8 Touchscreen issuesInternet Explorer + Windows8 触摸屏问题
【发布时间】:2013-04-19 06:58:50
【问题描述】:

我们遇到了与 Google Maps API V3 相关的问题。问题是,当我们拖动标记时,地图也会开始拖动。

我们仅在 Windows 8 环境 + Internet Explorer 的触摸屏上遇到此问题,在普通屏幕/移动屏幕 - IPaid/其他浏览器(Safari 和 FireFox)上正常。

我们使用了以下解决方案,但它在 Internet Explorer9 和 10 中引发错误 (eval javascript error):

google.maps.event.addListener(marker, 'dragstart', function(){
    mapObject.setOptions({ draggable: false });
});
google.maps.event.addListener(marker, 'dragend', function(){
    mapObject.setOptions({ draggable: true });
}); 

Sample code is here.

我们也在这里报告了这个问题: gmaps-api-issues

编辑:

我们也在这里发布了related question

【问题讨论】:

    标签: internet-explorer google-maps google-maps-api-3 windows-8 touchscreen


    【解决方案1】:

    终于取得了一些成功(地图仍然移动了一点,但目前可以忽略)!

    声明了两个变量:

    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;
        });
    

    当 Marker 被放下时(拖拽结束):

    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);
        }
    });
    

    Complete sample code is here.

    【讨论】:

      猜你喜欢
      • 2015-11-01
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多