利用百度地图开发时,如果要高效率地添加大量标记点,可用下面的方法:
var points = []; // 模拟添加很多个点 points.push(new BMap.Point(longitude, latitude)); points.push(new BMap.Point(longitude, latitude)); var pointCollection = new BMap.PointCollection(points, options); pointCollection.addEventListener('click', function (e) { var infoWindow = new BMap.InfoWindow(title, opts); map.openInfoWindow(infoWindow, new BMap.Point(e.point.lng, e.point.lat)); }); map.addOverlay(pointCollection);
核心就是将点加入 BMap.PointCollection,然后 addOverlay。