在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ 調(diào)用高德地圖js的api,給點(diǎn)標(biāo)記添加click事件

調(diào)用高德地圖js的api,給點(diǎn)標(biāo)記添加click事件

在項(xiàng)目中給高德地圖的點(diǎn)標(biāo)記添加點(diǎn)擊事件時(shí)報(bào)錯(cuò),詳情看下方代碼:
1.創(chuàng)建點(diǎn)標(biāo)記

new AMap.Marker({
icon: icon,//24px*26px
position: vue.customer[i].position,
title: vue.customer[i].name,
zIndex: 200,
clickable: true,
map: map
});

2.給點(diǎn)標(biāo)記添加點(diǎn)擊事件

var clickHandle = AMap.event.addListener(marker, 'click', function() {
console.log("1111")
});

3.點(diǎn)擊后報(bào)錯(cuò)

marker is not defined

回答
編輯回答
吢丕

沒(méi)玩過(guò)高德API,不過(guò)看你的代碼大概猜到問(wèn)題原因了:marker沒(méi)有定義。推斷應(yīng)該前面的new實(shí)例應(yīng)該賦值給marker

var marker = new AMap.Marker({
                icon: icon,//24px*26px
                position: vue.customer[i].position,
                title: vue.customer[i].name,
                zIndex: 200,
                clickable: true,
                map: map
               });
               
var clickHandle = AMap.event.addListener(marker, 'click', function() {
                                                            console.log("1111")
                                                          });              
2018年7月28日 22:34
編輯回答
瞄小懶
marker is not defined

marker對(duì)應(yīng)的是你要控制的標(biāo)記實(shí)體。

2018年1月12日 05:58