<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>百度地图开发示例</title>
<style type="text/css">
#map {
height: 400px;
width: 100%;
margin: 0 auto;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="http://api.map.baidu.com/api?v=2.0&ak=你的百度地图API密钥"></script>
<script>
// 创建地图实例
var map = new BMap.Map("map");
// 设置地图中心点
var point = new BMap.Point(116.404, 39.915);
map.centerAndZoom(point, 15);
<p>// 添加多个标记点
var points = [
{
lng: 116.404, lat: 39.915, title: &quot;点1&quot;, content: &quot;这是点1的详细信息&quot;
},
{
lng: 116.414, lat: 39.905, title: &quot;点2&quot;, content: &quot;这是点2的详细信息&quot;
},
{
lng: 116.424, lat: 39.895, title: &quot;点3&quot;, content: &quot;这是点3的详细信息&quot;
}
];</p>
<p>for (var i = 0; i &lt; points.length; i++) {
var marker = new BMap.Marker(new BMap.Point(points[i].lng, points[i].lat));
map.addOverlay(marker);</p>
<p>// 绑定点击事件,弹出信息窗口
marker.addEventListener(&quot;click&quot;, function(){
var infoBox = new BMapLib.InfoBox(map, &quot;<div style='width:200px;padding:10px 20px;'>&quot; + points[i].content + &quot;</div>&quot;, {
boxStyle : {
background : &quot;#fff&quot;,
borderRadius : &quot;5px&quot;,
boxShadow : &quot;0 0 10px #888&quot;,
width: &quot;300px&quot;
},
closeIconMargin: &quot;4px 4px 4px 4px&quot;,
enableAutoPan: true,
offset: new BMap.Size(0, -20)
});
infoBox.open(this);
});
}
</script></p>
</body>
</html>

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

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