<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>百度地图多点标注示例</title>
<style type="text/css">
#map {
width: 100%;
height: 500px;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=你的百度地图API密钥"></script>
</body>
</html>
<p>// 地图初始化
var map = new BMap.Map(&quot;map&quot;);
var point = new BMap.Point(116.404, 39.915); // 设置中心点坐标
map.centerAndZoom(point, 15); // 设置地图级别</p>
<p>// 添加多个点标注
var markers = [
{ x: 116.404, y: 39.915, content: &quot;这是第一个点&quot; },
{ x: 116.414, y: 39.925, content: &quot;这是第二个点&quot; },
{ x: 116.424, y: 39.935, content: &quot;这是第三个点&quot; }
];</p>
<p>for (var i = 0; i &lt; markers.length; i++) {
var marker = new BMap.Marker(new BMap.Point(markers[i].x, markers[i].y));
map.addOverlay(marker);</p>
<p>// 添加infoBox信息窗
var infoBox = new BMapLib.InfoBox(map, markers[i].content, {
boxStyle: {
width: &quot;200px&quot;,
height: &quot;80px&quot;
},
closeIconMargin: &quot;10px 2px 0 0&quot;,
enableAutoPan: true,
align: INFOBOX_AT_TOP
});</p>
<p>marker.addEventListener(&quot;click&quot;, function () {
infoBox.open(this);
});
}</p>
<p>// 启用滚轮缩放
map.enableScrollWheelZoom(true);</p>

原文地址: https://www.cveoy.top/t/topic/pNdj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录