W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
MapContext
實(shí)例,可通過 wx.createMapContext
獲取。MapContext
通過 id
跟一個(gè) map
組件綁定,操作對應(yīng)的 map
組件。
獲取當(dāng)前地圖中心的經(jīng)緯度。返回的是 gcj02
坐標(biāo)系,可以用于 wx.openLocation()
將地圖中心移置當(dāng)前定位點(diǎn),此時(shí)需設(shè)置地圖組件 show-location
為true
。2.8.0 起支持將地圖中心移動(dòng)到指定位置。
平移marker
,帶動(dòng)畫
縮放視野展示所有經(jīng)緯度
獲取當(dāng)前地圖的視野范圍
獲取當(dāng)前地圖的旋轉(zhuǎn)角
獲取當(dāng)前地圖的傾斜角
獲取當(dāng)前地圖的縮放級別
設(shè)置地圖中心點(diǎn)偏移,向后向下為增長,屏幕比例范圍(0.25~0.75),默認(rèn)偏移為[0.5, 0.5]
移除個(gè)性化圖層。
添加個(gè)性化圖層。
<!-- map.wxml -->
<map id="myMap" show-location />
<button type="primary" bindtap="getCenterLocation">獲取位置</button>
<button type="primary" bindtap="moveToLocation">移動(dòng)位置</button>
<button type="primary" bindtap="translateMarker">移動(dòng)標(biāo)注</button>
<button type="primary" bindtap="includePoints">縮放視野展示所有經(jīng)緯度</button>
// map.js
Page({
onReady: function (e) {
// 使用 wx.createMapContext 獲取 map 上下文
this.mapCtx = wx.createMapContext('myMap')
},
getCenterLocation: function () {
this.mapCtx.getCenterLocation({
success: function(res){
console.log(res.longitude)
console.log(res.latitude)
}
})
},
moveToLocation: function () {
this.mapCtx.moveToLocation()
},
translateMarker: function() {
this.mapCtx.translateMarker({
markerId: 0,
autoRotate: true,
duration: 1000,
destination: {
latitude:23.10229,
longitude:113.3345211,
},
animationEnd() {
console.log('animation end')
}
})
},
includePoints: function() {
this.mapCtx.includePoints({
padding: [10],
points: [{
latitude:23.10229,
longitude:113.3345211,
}, {
latitude:23.00229,
longitude:113.3345211,
}]
})
}
})
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: