Google maps alternative routes won't update

試著忘記壹切 提交于 2019-12-25 18:42:26

问题


I have created a directions map from one point to multiple specific point. When one change end point the map should update, and alternative routes should be shown on the right sidebar, with details under it. However, when I change end point it's not updating nicely, sometimes it just add alternative directions under "old" directions,sometimes alternatives are messed up, not really sure what the problem is, though I suspect that there might be a problem if theres's no alternative routes returned for the specific end point. Here's a preview of what I made so far:

jsbin.com/hoqebofice/edit?output  

Also in the end, I'd like to have map updated once alternative route is clicked from the right sidebar as well.


回答1:


In your OnChangeHandler add this line:

 var onChangeHandler = function() {
      document.getElementById("setPanel").innerHTML = ""; // THIS ONE!
      calculateAndDisplayRoute(directionsService, directionsDisplay);
    };


来源:https://stackoverflow.com/questions/48501875/google-maps-alternative-routes-wont-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!