remove route with google map

后端 未结 8 2069
半阙折子戏
半阙折子戏 2020-12-03 20:29

I got a small app that use the Direction Service feature of Google Map. It is working well, I can change routes, but I have a small problem, where a user could go back to a

8条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 21:11

    It's important - at least it was in my case - that while directionsDisplay can be declared globally the instance has to be created after the map object otherwise it gave a reference error

        var map;
        var directionsDisplay;
    
        function initMap() { 
    
            map = new google.maps.Map(...);
    
            directionsDisplay = new google.maps.DirectionsRenderer(...);
    
         }
    
         function yourFunction() {
    
            // your code
    
            directionsDisplay.addListener(...);
    
         }
    

提交回复
热议问题