【发布时间】:2018-03-11 00:30:38
【问题描述】:
我在谷歌地图的帮助下制作了这个应用程序,我成功地在一条路线中添加了waypoints 并在它们之间建立了一条路线。但是在dbclick 上,我从地图上删除了那个路点。现在,当我制作路线时,它也包含已删除的waypoint。因为它不会从waypoint 数组中删除。
问题是如何从航点数组中删除特定的waypoint。我没有任何index 的东西。
推送航路点
/* Whenever a user taps a pin it goes into pinwapypts */
pinwaypts.push({
location: $scope.destination_route,
stopover: true,
});
在地图中添加航点
infowindow.open($scope.map, marker);
$scope.markers.push(marker);
google.maps.event.addListener(marker, 'click', function () {
infowindow.setContent($scope.results[0].formatted_address);
infowindow.open($scope.map, this);
});
从地图上移除航点标记
google.maps.event.addListener(marker, 'dblclick', function () {
$scope.markers.pop().setMap(null);
});
现在我如何从其数组中删除特定的waypoint?
完整代码
function getClickLoc(latlng) {
var geocoder = new google.maps.Geocoder;
geocoder.geocode({
'location': latlng
}, function (results, status) {
$scope.results = results;
//console.log(results);
if (status === 'OK') {
if (results[0]) {
$scope.map.setZoom(12);
var marker = new google.maps.Marker({
position: latlng,
map: $scope.map
});
infowindow.setContent(results[0].formatted_address);
$scope.destination_route = latlng;
/* Whenever a user taps a pin it goes into pinwapypts */
pinwaypts.push({
location: latlng,
stopover: true
});
$scope.$apply();
infowindow.open($scope.map, marker);
$scope.markers.push(marker);
google.maps.event.addListener(marker, 'dblclick', function () {
infowindow.setContent($scope.results[0].formatted_address);
infowindow.open($scope.map, this);
});
google.maps.event.addListener(marker, 'dblclick', function () {
$scope.markers.pop().setMap(null);
});
//$ionicLoading.hide();
} else {
window.alert('No results found');
}
} else {
window.alert('Something went wrong, Please try again.');
//window.alert('Geocoder failed due to: ' + status);
}
});
}
【问题讨论】:
-
在您获得路线之前,对于您添加的每个航路点,都会以相同的顺序对应一个标记?
-
请看我的完整代码
标签: angularjs google-maps ionic-framework