【问题标题】:How to update pixelPosition of a custom infoWindows on Google Maps V3 after dragging?拖动后如何在 Google Maps V3 上更新自定义信息窗口的像素位置?
【发布时间】:2009-12-08 17:48:51
【问题描述】:

我正在 Google 地图之上创建一个新的混搭。这很简单,我选择使用 V3 来提供更长的使用寿命。

但是,Google Maps infoWindow 没有提供一些特殊需求。

我已经使用 marker.projectionContainer.pixelPosition 定位了我的自定义 infoWindow。缩放后我得到正确的位置,但拖动不会更新标记像素位置。拖动后如何获得标记旧位置和新位置之间的差异?

或

我应该使用OverlayView 而不是尝试从 DOM 中获取位置吗?我认为地图自己的 infoWindows 会自动更新/停在面板上。

【问题讨论】:

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


    【解决方案1】:

    这个答案假设拖动是指拖动标记而不是拖动地图,如果不是这样,请告诉我

    您应该使用 OverlayView,然后您可以使用 MVC 技术绑定到标记的位置属性。

    function MyOverlay(marker) {
      this.bindTo('position', marker);
    }
    MyOverlay.prototype = new google.maps.OverlayView();
    
    MyOverlay.prototype.position_changed = function() {
      this.draw();
    };
    
    MyOverLay.prototype.draw = function() {
      // This is where you recalculate the latLngToPixel stuff where latLng
      // is this.get('position');
    };
    

    您还需要实现 OverlayView 接口的其余部分:onAdd 和 onRemove。

    【讨论】:

    • 假设是正确的,当时我使用的解决方案类似于您提供的解决方案。谢谢!
    猜你喜欢
    • 2014-07-02
    • 1970-01-01
    • 1970-01-01
    • 2012-06-07
    • 2014-05-14
    • 2014-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多