百度地图实现多点标记,自动调整缩放等级
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html {width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
#allmap{width:100%;height:500px;}
p{margin-left:5px; font-size:14px;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=您的key"></script>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<title>给多个点添加信息窗口</title>
</head>
<body>
<div id="allmap"></div>
<p>点击标注点,可查看由纯文本构成的简单型信息窗口</p>
</body>
</html>
<script type="text/javascript">
map = new BMap.Map("allmap");
var bPoints = new Array();
map.centerAndZoom(new BMap.Point(116.417854,39.921988), 15);
map.addControl(new BMap.MapTypeControl());
map.enableScrollWheelZoom(true);
var data_info = [[116.417854,39.921988,"地址:北京市东城区王府井大街88号乐天银泰百货八层"],
[116.406605,39.921585,"地址:北京市东城区东华门大街"],
[116.412222,39.912345,"地址:北京市东城区正义路甲5号"]
];
addMarker(data_info);
function addMarker(data_info){
for(var i=0;i<data_info.length;i++){
var point = new BMap.Point(data_info[i][0],data_info[i][1]);
bPoints.push(point);
var marker = new BMap.Marker(point);
map.addOverlay(marker);
}
}
function setZoom(bPoints) {
var view = map.getViewport(eval(bPoints));
var mapZoom = view.zoom;
var centerPoint = view.center;
map.centerAndZoom(centerPoint, mapZoom);
}
setTimeout(function () {
setZoom(bPoints);
}, 1000)
</script>