知識(shí)
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們?cè)谧非笃湟曈X表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營銷的便利,運(yùn)營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏?jí)提供便捷的支持!
您當(dāng)前位置>首頁 » 新聞資訊 » 公眾號(hào)相關(guān) >
vue + 微信公眾號(hào)開發(fā)+騰訊地圖定位顯示附近商家多點(diǎn)標(biāo)記并自定義標(biāo)記樣式
發(fā)表時(shí)間:2020-9-24
發(fā)布人:葵宇科技
瀏覽次數(shù):189
先看下效果吧
首先進(jìn)行公眾號(hào)的常規(guī)開發(fā),引入jssdk,相關(guān)配置代碼如下
引入后可以使用微信內(nèi)置定位功能,獲取用戶經(jīng)緯度
重點(diǎn)!引入騰訊地圖JS API 點(diǎn)擊查看騰訊javascript API
在index.html頁引入jsapi
(key需要自己去騰訊地圖官網(wǎng)申請(qǐng)奧,否則鑒權(quán)不通過,不能進(jìn)行接下來的開發(fā))
創(chuàng)建一個(gè)需要用的地圖的組件,設(shè)置地圖寬高
js相關(guān)代碼如下
// 初始化地圖
initMap() {
this.mapSetting = {
Map: qq.maps.Map, // 構(gòu)建map的集合
Marker: qq.maps.Marker, // 地圖中的標(biāo)記
LatLng: qq.maps.LatLng, // 地圖中的經(jīng)緯度
Event: qq.maps.event, // 地圖事件
MVCArray: qq.maps.MVCArray, // 地圖中的可變數(shù)組
MarkerCluster: qq.maps.MarkerCluster // 地圖中點(diǎn)聚合(標(biāo)記聚合)
}
this.center = new this.mapSetting.LatLng(this.position.latitude, this.position.longitude)
var options = {
'zoom': 11,
'center': this.center,
'mapTypeId': 'roadmap'
}
// 創(chuàng)建map地圖
this.map = new this.mapSetting.Map(document.getElementById('map'), options)
// map的 info
this.info = new qq.maps.InfoWindow({
map: this.map
})
// 調(diào)用
this.createCluster()
this.initEvent()
},
// 地圖事件
initEvent() {
// 地圖縮放事件
// info.open('zoomLevel: ' + map.getZoom())
this.info.setPosition(this.center)
this.mapSetting.Event.addListener(this.map, 'zoom_changed', () => {
// todo 縮放時(shí) 分頁請(qǐng)求
// const zoomLevel = map.getZoom()
this.map.setCenter(this.center)
// info.setContent('zoomLevel: ' + zoomLevel)
})
// 點(diǎn)擊點(diǎn)聚合clusterer(聚類器)
this.mapSetting.Event.addListener(this.markerClusterer, 'clusterclick', function(evt) {
// console.log('e', evt)
})
},
// 創(chuàng)建makers
createCluster() {
if (this.map == null) {
return
}
var markers = new this.mapSetting.MVCArray()
for (var i = 0; i < this.testData.length; i++) {
const latLng = new this.mapSetting.LatLng(this.testData[i][0], this.testData[i][1])
var marker = new this.mapSetting.Marker({
'position': latLng,
map: this.map
})
// 獲取標(biāo)記的點(diǎn)擊事件
this.mapSetting.Event.addListener(marker, 'click', () => {
this.showInfo = true
this.info.open()
this.info.setContent(this.divInfo)
this.info.setPosition(latLng)
})
markers.push(marker)
}
this.markerClusterer = new this.mapSetting.MarkerCluster({
map: this.map,
minimumClusterSize: 8, // 默認(rèn)2
markers: markers,
zoomOnClick: true, // 默認(rèn)為true
gridSize: 30, // 默認(rèn)60
averageCenter: true, // 默認(rèn)false
maxZoom: 18 // 默認(rèn)18
})
}
自定義標(biāo)記樣式
在createCluster方法中新增這段代碼就可以實(shí)現(xiàn)了
效果如下
好啦,主要代碼就是這些,快去試試吧,歡迎大家留言溝通
相關(guān)案例查看更多
相關(guān)閱讀
- 網(wǎng)站建設(shè)費(fèi)用
- 云南網(wǎng)站設(shè)計(jì)
- 云南省住房建設(shè)廳網(wǎng)站
- 網(wǎng)站建設(shè)快速優(yōu)化
- 小程序表單
- 網(wǎng)絡(luò)公司排名
- 云南小程序哪家好
- 商標(biāo)
- 百度快速排名
- 北京小程序制作
- 云南網(wǎng)站建設(shè)選
- 區(qū)塊鏈
- 昆明網(wǎng)站設(shè)計(jì)
- 昆明小程序哪家好
- 云南網(wǎng)站建設(shè)高手
- 網(wǎng)站建設(shè)服務(wù)
- 云南網(wǎng)站建設(shè)公司排名
- 網(wǎng)絡(luò)公司報(bào)價(jià)
- 定制小程序開發(fā)
- 云南軟件定制公司
- asp網(wǎng)站
- 小程序被騙退款成功
- 云南花農(nóng)小程序
- painter
- 手機(jī)網(wǎng)站建設(shè)
- 網(wǎng)站建設(shè)電話
- 云南電商網(wǎng)站建設(shè)
- 云南做網(wǎng)站
- 云南小程序設(shè)計(jì)
- 文山小程序開發(fā)