【问题标题】:Angular UI Google Maps center markerAngular UI Google Maps 中心标记
【发布时间】:2015-11-04 20:33:56
【问题描述】:

我正在使用 Angular(UI)-Google-Maps (2.1.5) 和 AngularJS (1.3.13)

我想要一个始终位于地图中心的标记。问题是标记仅在我停止拖动时更新其位置。

我这样使用拖动事件:

drag: function(maps) {     
    $scope.map.marker.center.coords = $scope.map.center;
}

我还计算了数量,拖动事件触发的频率,远高于标记(或地图)的更新。这是一个例子:http://plnkr.co/edit/M39CFc

我也尝试了center_changedbounds_changed,结果相同。

【问题讨论】:

    标签: javascript angularjs google-maps google-maps-markers angular-ui


    【解决方案1】:

    要将标记放在地图的中心,请使用以下标签:

    <ui-gmap-marker coords="map.center" idkey="1" ng-cloak>
    

    虽然不鼓励这种技术,因为它也会在拖动地图时移动标记。要解决这种情况,请使用:

    marker.coords = Object.create(coords)
    

    【讨论】:

    • 很好用,但在移动设备上问题仍然存在。
    【解决方案2】:

    另一种可能性是将属性 draggable = true 添加到标记中:

     <ui-gmap-markers coords="'self'" icon="'icon'" options="{ draggable: true }">
    

    不知道为什么这解决了IE中的问题,check this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-18
      • 2015-09-03
      • 1970-01-01
      • 1970-01-01
      • 2021-09-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多