欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

调用百度报Cannot read property ‘lng‘ of null错误

发布时间:2023/12/31 编程问答 41 豆豆
生活随笔 收集整理的这篇文章主要介绍了 调用百度报Cannot read property ‘lng‘ of null错误 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

出错就是因为没有设置地图中心跟缩放等级
我用的是步行路线规划,在search之前加上centerAndZoom就没问题了

var map = new BMap.Map("container");map.centerAndZoom(new BMap.Point(116.404, 39.915), 14); //初始化地图var walking = new BMap.WalkingRoute(map, {renderOptions: {map: map,autoViewport: true}});// 地图的点击事件map.addEventListener('click', function (e) {var start = new BMap.Point(116.32427538375525, 39.98192077362723); //假定当前的位置在这里 海淀黄庄 var end = new BMap.Point(e.point.lng, e.point.lat);walking.search(start, end);});

解决~~

总结

以上是生活随笔为你收集整理的调用百度报Cannot read property ‘lng‘ of null错误的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。