使用js引入高德地圖
<script type="text/javascript">
var map = new AMap.Map('container', {
resizeEnable: true,
zoom:11,
center: [116.397428, 39.90923]//默認的地圖中心經緯度
});
// 在地圖上設置marker點
var markerTemp = new AMap.Marker({
position : [lng,lat], // 里面是經緯度
offset : new AMap.Pixel(-21,-21),//偏移量,默認以marker左上角位置為基准點
map : map
});
// 給marker里設置自定義屬性
markerTemp.id = "123";
// 給marker添加點擊事件,獲取獲取e對象
AMap.event.addListener(auto, "select", select);
function select(e) {
// 獲取存入的id
console.log(e.target.id);
var lng = e.poi.location.lng;
var lat = e.poi.location.lat;
console.log(e.poi.location.lng);
if (e.poi && e.poi.location) {
map.setZoom(15);
map.setCenter(e.poi.location);
addMarker(lng,lat);
}
}
</script>