AngularJS - 谷歌地图标记删除

时间:2014-12-11 22:20:41

标签: javascript android angularjs google-maps

无法找到解决方法如何使用uiGmapGoogleMapApi执行此操作。由于未导入google对象,因此无法使用常规解决方案。

我的标记通过以下方式更新:

$scope.change_type = function(val) {
        var markers = [];
        $scope.eventMarkers = markers
        var events = Events.venues(val.type)
        for (var i = 0; i < events.length; i++) {
            event = events[i]
            markers.push(createMarker(i,event))
        }
        $timeout(function(){$scope.eventMarkers = markers}, 100)

我的临时工作是创建超时足够长,以便在推送新内容之前进行更新,但这不是一个真正的解决方案,并且在实际设备上运行得不好。推送空阵列的标记也没有用。似乎我必须使用.setMap(null),但无法找到有关如何和在何处的任何文档。

1 个答案:

答案 0 :(得分:2)

&#13;
&#13;
// Removes the markers from the map, but keeps them in the array.
function clearMarkers() {
  setAllMap(null);

// Deletes all markers in the array by removing references to them.
function deleteMarkers() {
  clearMarkers();
  markers = [];
&#13;
&#13;
&#13;