高德地圖-添加自定義圖標
阿新 • • 發佈:2019-02-12
click 的人 icon 100% text 我們 posit cti user
3、實現結果
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="../js/jquery-1.12.3.js" ></script>
<script src="http://webapi.amap.com/maps?v=1.3&key=c2eb520334ddc5ab2bb70a3afe6a58cc"></script>
<script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
<style>
body,html{
width: 99%;
height: 99%;
font-family: "微軟雅黑";
font-size: 12px;
font-size-adjust: initial;
}
#keyMap{
width: 100%;
height : 100%;
font-family: "arial rounded mt bold";
font-size: -webkit-xxx-large;
}
</style>
</head>
<body>
<div id="keyMap"></div>
<div class="button-group">
<input type="button" class="button" id="addTag" value="添加點標記"/>
</div>
<script>
var marker;
var map = new AMap.Map("keyMap",{
resizeEnable: true,
center: [114.297199,30.573714],
zoom: 13
});
AMap.event.addDomListener(document.getElementById(‘addTag‘), ‘click‘, function() {
addTags();
}, false);
function addTags()
{
if(marker)
{
return;
}
marker = new AMap.Marker({
icon:"../img/ooopic_1464187636.png",
position:[114.297199,30.573714]
});
marker.setMap(map);
}
</script>
</body>
</html>
3、實現結果
(1)初始化時
(2)點擊“添加點標記”
再分享一下我老師大神的人工智能教程吧。零基礎!通俗易懂!風趣幽默!還帶黃段子!希望你也加入到我們人工智能的隊伍中來!https://blog.csdn.net/jiangjunshow
高德地圖-添加自定義圖標