【发布时间】:2016-06-29 15:20:18
【问题描述】:
我正在使用 angular-google-maps 库,但当我向模型动态添加新标记时,我似乎无法更新地图。模型中的硬编码标记正确显示。
HTML
<ui-gmap-markers models="map.placeMarkers" coords="'self'" icon="'icon'" options="'options'" click="'onClicked'" modelsbyref="true"></ui-gmap-markers>
JS
$scope.map.placeMarkers = [
{
id: 1,
latitude: 45,
longitude: -74,
options: {},
title: 'Test 123'
},
{
id: 2,
latitude: 15,
longitude: 30,
options: {},
title: 'Test 1234'
}
];
上面的工作正常但是当我这样做时:
var place = {
id: 3,
latitude: 455,
longitude: -574,
options: {},
title: 'Test 1233455'
};
$scope.map.placeMarkers.push(place);
模型已更新,但地图未更新。我曾尝试使用 $scope.$apply(),但由于摘要循环已在进行中,因此出现错误。
【问题讨论】:
-
试试下面的链接。这是一个使用 Angular js 动态添加标记的工作示例。按照这个例子,希望它对你有用:) LINK
-
我有同样的问题,你有解决方案吗? Ben_hawk
-
是的,我已经很久没有使用这个库了,但是如果我没记错的话,性能已经发生了变化。您需要更改数组引用才能刷新地图。尝试在您的位置数组上使用角度副本并在地图位置属性上设置结果。让我知道它是否有效。
标签: angularjs google-maps angular-google-maps