使用高德地圖時,通過搜索便可將地址搜索出來,但是想點擊當前marker獲取當前的經緯度和具體地址時,如下圖:
AMap.event.addListener(autocomplete, "select", function(e){
//TODO 針對選中的poi實現自己的功能
placeSearch.search(e.poi.name);
//這是實現搜索功能
});
//以下代碼實現marker的點擊事件獲取相關信息
//點擊事件
AMap.event.addListener(placeSearch, "markerClick", function(e){
console.log(e.data.location);//當前marker的經緯度信息
document.getElementById("lnglat").value = e.data.location.lng + ',' + e.data.location.lat;
console.log( e.data.address);//獲取當前marker的具體地址信息
console.log(e.data);//則是包含所有的marker數據
document.getElementById("input").value = e.data.address;
這樣就可將點擊的當前的marker所有信息獲取然後做處理
更多方法可參考高德地圖JavaScript API
http://lbs.amap.com/api/javascript-api/summary