Documentation de développement de l'applet WeChat
/ 微信小程序API 地圖組件控制
微信小程序API 地圖組件控制
wx.createMapContext(mapId)
創(chuàng)建并返回 map 上下文 mapContext
對(duì)象
mapContext
mapContext
通過(guò) mapId 跟一個(gè) <map/>
組件綁定,通過(guò)它可以操作對(duì)應(yīng)的 <map/>
組件。
mapContext 對(duì)象的方法列表
getCenterLocation 的 OBJECT 參數(shù)列表
示例代碼:
<!-- map.wxml --> <map id="myMap" show-location /> <button type="primary" bindtap="getCenterLocation">獲取位置</button> <button type="primary" bindtap="moveToLocation">移動(dò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() } })