【发布时间】:2015-05-30 16:15:21
【问题描述】:
我的 html 页面通过以下方式呈现地图:
<ui-gmap-google-map center='map.center' zoom='map.zoom'>
<ui-gmap-markers models="markers" coords="'coords'" icon="'icon'" ></ui-gmap-markers>
</ui-gmap-google-map>
这是控制器:
angular.module('controllers.mapscontroller', [])
.controller("MapCtrl", function($scope, uiGmapGoogleMapApi, dataFactory) {
$scope.POIs=[];
$scope.markers = [];
uiGmapGoogleMapApi.then(function(maps) {
$scope.map = { center: { latitude: 40.3555013, longitude: 18.1573811 }, zoom: 8 };
navigator.geolocation.getCurrentPosition(function (position) {
$scope.map = { center: { latitude: position.coords.latitude, longitude: position.coords.longitude }, zoom: 8 };
});
dataFactory.getPOIs("it-IT")
.success(function (data) {
$scope.POIs=data.data.contents;
$scope.initializePOIsOnMap();
})
.error(function (error) {
console.log(error);
});
});
$scope.removePOIs = function() {
$scope.markers=[]; //<-- does nothing !!!
};
$scope.initializePOIsOnMap = function() {
for(var POI in $scope.POIs) {
var marker = {
id: $scope.POIs[POI].id,
coords: {
latitude: $scope.POIs[POI].latitude,
longitude: $scope.POIs[POI].longitude
},
options: { draggable: false , visible:true},
icon: "img/catIcons/"+$scope.POIs[POI].catid+".png"
};
$scope.markers.push(marker);
}
}
});
地图可以正确显示,标记也可以正确显示。 但不幸的是,正如您在 $scope.removePOIs 函数中看到的那样,我无法从地图中删除标记。我尝试了在 stackoverflow 和 Web 上找到的不同解决方案($scope.markers.length=0, marker.setMap(null), ...),但没有运气。
有什么提示吗?? 谢谢 罗伯托
【问题讨论】:
标签: angularjs google-maps marker ionic