directionsRender.setPanel(this.directionsPanel.nativeElement);不会重置为null。如何解决?

时间:2019-03-30 13:15:56

标签: google-maps ionic-framework ionic3

我正在使用directionsRender.setPanel(this.directionsPanel.nativeElement);显示从a到b的方向。路线会显示并起作用,但是每当我输入新路线时,路线都会正确更新并显示新路线,但也会显示旧路线。我该如何解决

我尝试将其设置为null似乎不起作用

DisplayAndAnimateRoute() {
let here = this;

let directionsProvider = new google.maps.DirectionsService;
let directionsRender = new google.maps.DirectionsRenderer;
// directionsRender.set('directions', null);


const map = new google.maps.Map(document.getElementById('map'), {
  zoom: 10,
  center: {lat: number, lng: -number},
  draggable:false,
  // tilt:true,
  // scroll:true
});
directionsRender.setMap(map);
directionsRender.setPanel(this.directionsPanel.nativeElement);
console.log("From :",this.From);

if(this.From == null || this.From=='' ||this.From == isUndefined || this.From == 'My Location' || this.From == 'my location' || this.From == 'My location'){
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      let pos = {
        lat: position.coords.latitude,
        lng: position.coords.longitude
      };
      map.setCenter(pos);
      here.MyLocation = new google.maps.LatLng(pos);
      //alert(JSON.stringify(pos) );
    }, function() {

    });
  } else {
    // Browser doesn't support Geolocation
    // Give Notifications or your actions
  }
}else{
  here.MyLocation = this.From;
}

0 个答案:

没有答案