本文章是在uniapp開發(fā)的微信小程序中使用騰訊地圖,在地圖上添加標(biāo)記
// 添加地圖標(biāo)記的方法
?? ?addMarkers(driverList) {? ?//driverList為需要添加到地圖標(biāo)記上的司機(jī)數(shù)組
?? ??? ??? ??? ?const markers = []? ?//地圖標(biāo)記數(shù)組
?? ??? ??? ??? ?driverList.forEach(item => {
?? ??? ??? ??? ??? ?markers.push({
?? ??? ??? ??? ??? ??? ?id: item.driverId, // 唯一標(biāo)識(shí)符
?? ??? ??? ??? ??? ??? ?latitude: item.latitude,//緯度
?? ??? ??? ??? ??? ??? ?longitude: item.longitude,//經(jīng)度
?? ??? ??? ??? ??? ??? ?width: 20,//地圖icon的寬度
?? ??? ??? ??? ??? ??? ?height: 20,//地圖icon的高度
?? ??? ??? ??? ??? ??? ?label: {? ? ? //標(biāo)記的提示文字的樣式
?? ??? ??? ??? ??? ??? ??? ?width: 50,
?? ??? ??? ??? ??? ??? ??? ?height: 30,
?? ??? ??? ??? ??? ??? ??? ?borderRadius: 10,
?? ??? ??? ??? ??? ??? ??? ?content: item.nickName,//提示內(nèi)容
?? ??? ??? ??? ??? ??? ??? ?color: '#fff',
?? ??? ??? ??? ??? ??? ??? ?bgColor: '#8cc540'
?? ??? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ?})
?? ??? ??? ??? ?})
?? ??? ??? ??? ?uni.createMapContext("isMap", this).addMarkers({? ?//調(diào)用uniapp地圖組件的方法,進(jìn)行標(biāo)記,“isMap”為地圖組件的id
?? ??? ??? ??? ??? ?markers,? ?//需要標(biāo)記的數(shù)組
?? ??? ??? ??? ??? ?clear: true,//標(biāo)記時(shí),是否清除上一次留下來的標(biāo)記
?? ??? ??? ??? ?})
?? ??? ??? ?},
效果如圖所示
文章來源:http://www.zghlxwxcb.cn/news/detail-721269.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-721269.html
到了這里,關(guān)于微信小程序地圖添加marker的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!