【问题标题】:Markers incorrectly changing location on zoom标记在缩放时不正确地改变位置
【发布时间】:2011-07-09 02:43:20
【问题描述】:

我将一组标记添加到缩放级别为 15 的地图中。标记 lat 和 lng 当前设置为小数点后 6 位。

当我放大或缩小标记位置时,它们会移出正确的位置。我需要在每个缩放级别删除并重绘标记吗?我需要提高坐标的准确性吗?这快把我逼疯了……

测试页面:http://m.uwosh.edu/api/v1.0/map/ 点击底部栏中的黄色图标。

我正在像这样创建我的标记:

function createMarker(data, type) 
{
  var posn = new google.maps.LatLng(data.lat,data.lng);
  var title = data.title;
  var image,shadow,shape;
  if (data.typeId === '101') {
      image = new google.maps.MarkerImage('/api/v1.0/map/images/buildings.png',
      // This marker is 20 pixels wide by 32 pixels tall.
      new google.maps.Size(24, 28),
      // The origin for this image is 0,0.
      new google.maps.Point(0,0),
      // The anchor for this image is the base of the flagpole at 0,32.
      new google.maps.Point(0, 28));
    shadow = new google.maps.MarkerImage('/api/v1.0/map/images/shadow-buildings.png',
      // The shadow image is larger in the horizontal dimension
      // while the position and offset are the same as for the main image.
      new google.maps.Size(39, 28),
      new google.maps.Point(0,0),
      new google.maps.Point(0, 28));

  } 
  var markerOptions = {
    position: posn,
    title: title,
    shadow: shadow,
    icon: image
};

var marker = new google.maps.Marker(markerOptions);

    // could add event handler here

    //add marker to array for latter use
    if (type === 'building') {
       buildingMarkers.push(marker);
    }
}

【问题讨论】:

    标签: google-maps google-maps-api-3 google-maps-markers


    【解决方案1】:

    您不必添加/删除标记,因为标记放置在纬度/经度位置。

    也许一些代码可以帮助我们解决这个问题。

    【讨论】:

    • 确定我在正文中添加了指向我的测试站点的链接
    • 因为您的回答是正确的,所以给予您信任。如果你不弄乱图标连接点,它就不会移动。
    • 我不确定他们是否真的在“移动”我在 chrome 上测试了你的页面。标记并没有完全移动。他们停留在修复位置,他们被告知通过纬度/经度位置绘制。因为您正在放大地图的不同部分,从而扩大了可视区域,所以标记需要保持其相对于您正在放大的位置的位置。如果您使用鼠标滚轮放大标记,您会注意到该标记没有移动。但是,如果您放大另一个区域,它会这样做,因为它会保持您的代码定义的纬度/经度位置。
    • @JKM,你能澄清一下吗?我遇到了同样的问题,根据您的最后评论,我无法确定是否有修复。我将标记位置设置为 LatLng,当我拖动地图(因此标记不在屏幕上)并缩放,然后将地图拖回原始视图时,标记图像偏移了我拖动的距离地图。标记的实际坐标没有改变,只是标记图像的显示位置。
    • @byron 在 h3r2on 的情况下,标记被赋予了错误的纬度/经度值。标记根本不动。您是否在其他浏览器中进行过测试?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-16
    • 2012-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多