Когда я загружаю несколько маршрутов, предыдущий маршрут не удаляется. Многие люди сказали установить directionsDisplay.setMap
на null
, но это не работает. Похоже, что маршрут указан на карте, а не на directionsDisplay
. Это мой код, который не работает:Как я могу очистить маршруты на google.map?
NgMap.getMap('mapShop').then(function(map) {
$scope.googleMaps = map;
var directionsDisplay = new google.maps.DirectionsRenderer();
var directionsService = new google.maps.DirectionsService();
directionsDisplay.setMap(null);
directionsDisplay.setDirections(null);
directionsDisplay.setMap($scope.googleMaps);
// get geolocation for center map and marker
NavigatorGeolocation.getCurrentPosition().then(function(position) {
$scope.latitude = $routeParams.latitude;
$scope.longitude = $routeParams.longitude;
$scope.urlLocalCard = "http://maps.apple.com/?daddr=" + $routeParams.latitude + "," + $routeParams.longitude + "&saddr=" + position.coords.latitude + "," + position.coords.longitude + "&ll=" + $routeParams.latitude + "," + $routeParams.longitude + "&z=10&t=s";
var request = {
origin: position.coords.latitude + ',' + position.coords.longitude,
destination: $routeParams.latitude + ',' + $routeParams.longitude,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status === google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
} else {
alert('Google route unsuccesfull!');
}
});
});
Какие ошибки вы видите в консоли JS? –
В консоли отображаются все ошибки. –
Что это значит? –