Google地图拖动事件不会捕获中心更改,直到在Chrome设备模式下拖动结束 [英] Google Maps drag event doesn't capture center change until dragging ends in Chrome Device Mode

查看:499
本文介绍了Google地图拖动事件不会捕获中心更改,直到在Chrome设备模式下拖动结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用角度Google地图将一个地图在我的网络应用程序。我正在侦听成功触发的拖动事件,但拖动之后地图的中心属性不会更新停止。这是预期的行为?

  $ scope.map = {
center:$ scope.currentCoords我找不到任何文档来确认。


control:{},
zoom:15,
events:{drag:function(m,e,args){mapDragged(m,e,args)}}
};

var mapDragged = function(map,eventName,args){
console.log($ scope.map.center); //这个值只在拖动停止并重新启动时发生变化

$ c $
$ b $ p $ UPDATE



我试图在本例中使用本地Google地图事件,它似乎捕获地图中心的变化,但这仍然无效。 'center_changed'事件只会在停止拖动后触发,而不会在示例

  google.maps.event.addListener($ scope.map。 control.getGMap(),'center_changed',function(){
console.log($ scope.map.control.getGMap()。getCenter()。toUrlValue());
});

更新2



当我将Chrome开发者工具设置为未设置为设备模式时,它看起来像一切正常。预期的用法是在移动设备上,所以需要找到一种方法来完成这项工作......

解决方案

行为被问及这里



虽然我不能在API文档中具体提及完整浏览器和设备之间的区别,前面提到的问题链接指向一个特定于事件的Maps API示例,它可以完全按照您所描述的方式说明行为。



在非设备模式, center_changed 会在地图拖动时继续触发。



在设备模式下,它不会。当地图被拖动时,只有拖动 mousemove 会发生火灾。我也在Droid和iPhone的实际设备上证实了这种行为。



既然如此,我可以说假设这是一个预期的,虽然没有记录的行为是安全的。


I'm using Angular Google Maps to include a map in my web app. I am listening to the drag event which fires successfully but the center property of the map doesn't update until the dragging stops. Is this the expected behavior? I couldn't find any docs to confirm.

$scope.map = {
    center: $scope.currentCoords,
    control: {},
    zoom: 15,
    events: {drag: function(m, e, args){mapDragged(m, e, args)}}
};

var mapDragged = function(map, eventName, args){
    console.log($scope.map.center); // this value only changes when dragging stops and restarts
}

UPDATE

I tried to use the native google maps events in this example that seem to capture the change in the center of the map but this still doesn't work. The 'center_changed' event only fires after the drag stops and not like in the example

google.maps.event.addListener($scope.map.control.getGMap(), 'center_changed',function() {
    console.log($scope.map.control.getGMap().getCenter().toUrlValue());
});

UPDATE 2

It looks like everything works fine when I have the chrome developer tools NOT SET to a DEVICE MODE. The intended usage is on mobile so need to find a way to make this work...

解决方案

A similar question about this same behavior was asked here.

And though I can't find specific mention in the API docs about the differences between full browsers and devices, the aforementioned question links to a Maps API example specific to events, which illustrates the behavior exactly as you've described.

In non-device mode, center_changed continues to fire as the map is dragged.

In device mode, it does not. Only drag and mousemove fire while the map is being dragged. I also confirmed this behavior on actual devices, both Droid and iPhone.

That being the case, I would say it's safe to assume this is an expected, albeit undocumented, behavior.

这篇关于Google地图拖动事件不会捕获中心更改,直到在Chrome设备模式下拖动结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆