将Google地图标记拖到地图中心时拖动? [英] Keep Google Maps marker in centre of map while dragged?

查看:133
本文介绍了将Google地图标记拖到地图中心时拖动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Google地图的中心显示一些十字线。

I'd like to display some crosshairs in the very centre of a Google Map.

目前我有这样的代码:

Currently I have code like this:

        var mapCentre = map.getCenter();
        reticleMarker = new google.maps.Marker({
            position: mapCentre,
            map: map,
            icon: reticleImage, 
            shape: reticleShape,
            optimized: false,
            zIndex: 5
        });
        google.maps.event.addListener(map, 'bounds_changed',
           function(){reticleMarker.setPosition(map.getCenter());});  

在桌面上运行良好,但在移动设备上无法运行。在移动时,当用户的手指拖动地图时,十字线不会留在地图的中心。

Works great on a desktop, but not on mobile. On mobile the crosshairs don't stay in the centre of the map while the user's finger is dragging the map.

使用拖动事件监听程序并不会奏效。

Using a drag event listener doesn't work any better.

任何人都可以建议如何在移动浏览器中处理这个问题吗? (作为参考,我在Android浏览器中看到了这个问题。)

Could anyone suggest how to deal with this in mobile browsers? (For reference, I'm seeing this problem in an Android browser.)

我想或许我应该在CSS中显示十字线,而不是地图标记?

I'm thinking perhaps I should display the crosshairs in CSS, rather than as a map marker?

推荐答案


我想或许我应该在CSS中显示十字线而不是地图marker?

I'm thinking perhaps I should display the crosshairs in CSS, rather than as a map marker?

我使用了类似的方法来取得很好的效果。您可以将任何HTML放入地图容器中,Google Maps不会介意。

I've used a similar approach to great effect. You can put any HTML you want in the maps container, Google Maps wont mind.

这篇关于将Google地图标记拖到地图中心时拖动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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