Fit Baidu map to multiple markers like Google Maps fitBounds

醉酒当歌 提交于 2019-12-06 07:55:18

Just stumbling upon this thread. The answer to this question is:

var points = [Point_1,...,Point_n];
map.setViewport(points);

points is simply an array containing objects of type BMap.Point that you want within the map viewport.

Docs: http://developer.baidu.com/map/reference/index.php?title=Class:%E6%80%BB%E7%B1%BB/%E6%A0%B8%E5%BF%83%E7%B1%BB

It is possible to show multiple markers on Baidu Map.

Check their example here

I have displayed Baidu Map with an area of 230x125 so I have shown the China on the area like below:

var map     = new BMap.Map("id_of_map_loading_area");
var point   = new BMap.Point(101.841797,35.433724); //China on the center of the area
map.centerAndZoom(point,3);  // Change value 3 to see difference
map.enableScrollWheelZoom(); // Zoom effect to the map using mouse.

Although this answer worked for me, with the change of direct latlng object instead of BMap.Point object to make it work.

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