这个 百度 给我们 提供了 api 直接就是封装在 Bmap 构造的函数中, 得到的数据 可能不是我们想要的 结果 我们稍微处理下 就行
一般都是 保存后小数点后两位
map.getDistance();
我这里稍微封装好了
可以直接使用
// 百度地图 计算 其他点和 中心点的距离
function getDistance(centerPoint, otherPoint) {
var distance = map.getDistance(centerPoint, otherPoint);
return (distance / 1000).toFixed(2) + "km"
}
然后就是直接 使用了 渲染到页面上的效果 就是下图的这样的效果了
关注我 持续更新前端知识