老师,请检查
来源:5-4 自由编程
慕桂英1352525
2021-07-17 12:00:19
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#container{
height:900px;
width:900px;
}
.amap-icon img{
height:30px;
width:30px;
}
</style>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=e0518a145a65b2ceff33e4fbd171e3ab"></script>
</head>
<body>
<div id="container"></div>
<script>
var map=new AMap.Map('container',{
center:[116.379391,39.861536],
zoom:18
})
map.setDefaultCursor('pointer');
var marker=new AMap.Marker({
icon:'https://a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
position:[116.379391,39.861536]
})
marker.setMap(map)
map.on('click',function(e){
if(marker){
marker.setMap(null)
}
marker=new AMap.Marker({
icon:'https://a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
position:[e.lnglat.lng,e.lnglat.lat]
})
marker.setMap(map)
})
</script>
</body>
</html>
1回答
好帮手慕星星
2021-07-17
同学你好,代码实现效果很棒。继续加油,祝学习愉快!
相似问题