高德地圖-展示多個信息窗口
阿新 • • 發佈:2019-02-16
title meta init http 信息 ext comm pixel https
1、問題背景
高德地圖,設置小圖標,並點擊圖標顯示信息
2、實現源碼
<!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="http://cache.amap.com/lbs/static/main1119.css"/>
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=key值"></script>
<script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"> </script>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
//初始化地圖對象,加載地圖
var map = new AMap.Map("container", {
resizeEnable: true,
zoom:10
});
//經度緯度
var lnglats = [
[114.069919 ,30.564255],
[114.461307,30.618634],
[114.509372,30.492096],
[114.525165,30.742646],
[114.620609,30.712543],
[114.547138,30.412779],
[113.902378,30.396789],
[114.15163,30.779228],
[114.676227,30.857067],
[114.162616,30.96782]
];
//人員信息
var student = [
{name:"張思",age:"22",sex:"女"},
{name:"李磊",age:"21",sex:"男"},
{name:"吳雪",age:"22",sex:"女"},
{name:"思雨",age:"23",sex:"女"},
{name:"趙華",age:"24",sex:"男"},
{name:"孫楊",age:"26",sex:"男"},
{name:"錢思思",age:"20",sex:"女"},
{name:"鄭武",age:"22",sex:"男"},
{name:"胡迪",age:"21",sex:"男"},
{name:"司馬雲",age:"22",sex:"女"}
];
//初始化信息窗口
var infoWindow = new AMap.InfoWindow({offset: new AMap.Pixel(0, -30)});
//循環遍歷
for (var i = 0, marker; i < lnglats.length; i++)
{
var marker = new AMap.Marker({
position: lnglats[i],
map: map
});
marker.content = "人員位置<br><br>姓名:"+student[i].name+"<br>年齡:"+student[i].age+"<br>性別:"+student[i].sex;
marker.on(‘click‘, markerClick);
marker.emit(‘click‘, {target: marker});
}
//點擊事件
function markerClick(e)
{
infoWindow.setContent(e.target.content);
infoWindow.open(map, e.target.getPosition());
}
map.setFitView();
</script>
</body>
</html>
3、實現結果
再分享一下我老師大神的人工智能教程吧。零基礎!通俗易懂!風趣幽默!還帶黃段子!希望你也加入到我們人工智能的隊伍中來!https://blog.csdn.net/jiangjunshow
高德地圖-展示多個信息窗口