<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>批量逆地理编码</title>
<link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
<style>
html,body,#container{
height:100%;
width:100%;
}
.btn{
width:10rem;
margin-left:3.8rem;
}
.input-item-text{
background-color:white;
padding-left:4px;
width:12rem;
}
.mark{
width:19px;
height: 31px;
color:white;
text-align: center;
line-height: 21px;
background: url('https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png');
}
</style>
</head>
<body>
<div id="container"></div>
//替换自己的key值(高德地图)
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=你的Key&plugin=AMap.Geocoder"></script>
<script type="text/javascript">
//初始化地图
var map = new AMap.Map("container", {
zoom: 0,
resizeEnable: true
});
//标记数组
var markers = [];
//假设这是从后端传来的数据
var lnglats = [[120.2651,29.1777], [114.02207,22.702], [102.1929,12.6700], [96.1407,16.9296]];
//进行循环
for (var i = 0; i < lnglats.length; i += 1) {
//图标大小
var icon = new AMap.Icon({
image: 'img/mark_b.png',//图标图片
size: new AMap.Size(24, 24)
});
//添加MArker点
var marker = new AMap.Marker({
icon: icon,//图标
position: lnglats[i],//经纬度
//标记的内容为
content: '<div class="mark">' + i + '</div>',
map: map
});
markers.push(marker);
map.add(marker);
}
</script>
</body>
</html>
这是最后的效果