高德地图做汽车路线规划的时候清除之前的路线

在做这个汽车路线规划的时候遇到的问题:就是汽车位置到起点的路线,然后变成汽车位置从起点至终点,那么汽车位置到起点的路线没有清除,还留在上面,要强制刷新页面才能清除!这样当然是不行的!!!

解决办法就是调用这个方法

// 清除所有覆盖物,只要用这个就可以了,
this.map.clearMap()

调用这个方法后就可以看到效果了,我用的react,是在componentWillReceiveProps里调用的

这里的this.map就是你初始化地图的代码


// 获取两地经纬度的中点
    const centerlatitude = (parseFloat(driver.latitude) + parseFloat(destination.latitude)) / 2
    const centerlongitude = (parseFloat(driver.longitude) + parseFloat(destination.longitude)) / 2
// 初始化地图
    this.map = new Map(this.mapNode, {
      center: [centerlongitude, centerlatitude],
      resizeEnable: true,
      expandZoomRange:true,
      zoom:19,
      zooms:[3, 19],
    })
发布了115 篇原创文章 · 获赞 38 · 访问量 43万+

猜你喜欢

转载自blog.csdn.net/wangweiscsdn/article/details/92976376