Remove directions from google map api v3

后端 未结 6 1688
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-29 18:58

I have a google map using API v3 which gets directions from one location to another. The app works great but the window which gets the directions is an overlay on the map.

相关标签:
6条回答
  • 2020-12-29 19:30

    You can change the map binding for the DirectionsRenderer to "null" to remove the direction overlay

    directionDisplay.setMap(null);
    
    0 讨论(0)
  • 2020-12-29 19:32

    You can also use : directionsDisplay.setDirections({routes: []});

    0 讨论(0)
  • 2020-12-29 19:32

    None of the above worked for me, this is what I needed:

    // Clear past routes
        if (directionsDisplay != null) {
            directionsDisplay.setMap(null);
            directionsDisplay = null;
        }
    
    0 讨论(0)
  • 2020-12-29 19:36

    Using directionDisplay.setMap(null); will remove the whole directions renderer overlay, including markers. If you just want to remove the routes keeping the markers you can use setOptions to change the options settings of DirectionsRenderer for suppressPolylines after initialization

    directionsDisplay.setOptions({
        suppressPolylines: true
      });
    

    (see also my other similar answer)

    0 讨论(0)
  • 2020-12-29 19:41

    That should read as:

    directionDisplay.setMap(null);
    
    0 讨论(0)
  • 2020-12-29 19:42

    You can try this, and not lose reference to the map

    directionDisplay.set('directions', null);
    
    0 讨论(0)
提交回复
热议问题