【发布时间】:2013-10-20 01:43:23
【问题描述】:
更准确地说,我试图实现的是,当我拖动 Google 地图时,会有一个 Google 地图标记 始终固定在地图的中心。 我认为这将改善用户体验,这就是我现在的做法:
var map, marker, options;
options = {
center: new google.maps.LatLng(latitude, longitude),
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
overviewMapControl: false,
zoomControl: true,
draggable: true
};
map = new google.maps.Map(mapContainer, options);
marker = new google.maps.Marker({
position: new google.maps.LatLng(latitude, longitude),
map: map,
animation: google.maps.Animation.DROP
});
//This line is what makes the Marker stick to the center of the map
marker.bindTo('position', map, 'center');
上面代码的问题是……当我将地图拖到标记下方时不够平滑,即。拖动结束时,标记会从“最后一个”中心到“新”中心进行一个奇怪的跳转。 (这在移动设备上更为明显),因此我需要的是标记真正永久固定到其地图的中心。
有没有办法做到这一点? (我想我曾经在一个网站上看到过这个)
如果你们可以帮助我,请告诉我。
谢谢。
【问题讨论】:
-
您是否尝试将 google.maps.Marker 的位置绑定到 google.maps.Map 对象的 center 属性?
-
否定,先生,我在阅读文档后能想到的唯一解决方案就是您在那里看到的解决方案。如果你能教我如何做你所描述的,我将不胜感激。
-
其实我觉得我现在正在做的事情是这样的?对吗?
-
是的。和it works for me。它不适合你吗?
-
不是标记在@geocodezip给出的链接上跳转
标签: javascript google-maps mobile google-maps-api-3