Jakub Balicki
Jakub Balicki

Reputation: 55

Remove directions from google map api

So I created in Ionic with Google map API, app that shows direction from place A to B. But I don't know how to clean it from the map.

I have got a button that starts startNavigating()

here is my .ts function of this:

 startNavigating(){

    let directionsService = new google.maps.DirectionsService;
    let directionsDisplay = new google.maps.DirectionsRenderer;
    

    directionsDisplay.setMap(this.map);
    directionsDisplay.setPanel(this.directionsPanel.nativeElement);

    directionsService.route({
        origin: this.StartN,
        destination: this.EndN,
        travelMode: google.maps.TravelMode['DRIVING']
    }, (res, status) => {

        if(status == google.maps.DirectionsStatus.OK){
            directionsDisplay.setDirections(res);
        } else {
            console.warn(status);
        }

    });

    let mapOptions = {
      zoom: 15,
    }; 

  
}

I would like to create a button which would start "clean()" and would remove this direction.

Thanks for help!

Upvotes: 0

Views: 585

Answers (1)

leo_henrique
leo_henrique

Reputation: 36

You can use this:

directionsDisplay.setMap(null);

Upvotes: 2

Related Questions