高德地圖在marker里設置自定義屬性


使用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>


 
         
         
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM