微信小程序8 位置与设备api
来源:互联网 发布:矩阵制组织结构的特点 编辑:程序博客网 时间:2024/09/21 06:36
位置
wx.getLocation(OBJECT)
获取当前的地理位置、速度。当用户离开小程序后,此接口无法调用;当用户点击“显示在聊天顶部”时,此接口可继续调用wx.getLocation({ type: 'wgs84', success: function(res) { var latitude = res.latitude var longitude = res.longitude var speed = res.speed var accuracy = res.accuracy }})
wx.chooseLocation(OBJECT)
打开地图选择位置。
wx.openLocation(OBJECT)
使用微信内置地图查看位置。
wx.getLocation({ type: 'gcj02', //返回可以用于wx.openLocation的经纬度 success: function(res) { var latitude = res.latitude var longitude = res.longitude wx.openLocation({ latitude: latitude, longitude: longitude, scale: 28 }) }})
wx.createMapContext(mapId)
创建并返回 map 上下文 mapContext
对象
<!-- map.wxml --><map id="myMap" show-location /><button type="primary" bindtap="getCenterLocation">获取位置</button><button type="primary" bindtap="moveToLocation">移动位置</button><button type="primary" bindtap="translateMarker">移动标注</button><button type="primary" bindtap="includePoints">缩放视野展示所有经纬度</button>
// map.jsPage({ 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, }] }) }})
方法 参数 说明 最低版本
wx.openLocation
moveToLocation无将地图中心移动到当前定位点,需要配合map组件的show-location使用 translateMarkerOBJECT平移marker,带动画1.2.0includePointsOBJECT缩放视野展示所有经纬度1.2.0getRegionOBJECT获取当前地图的视野范围1.4.0getScaleOBJECT获取当前地图的缩放级别translateMarker 的 OBJECT 参数列表
includePoints 的 OBJECT 参数列表
设备
wx.getSystemInfo(OBJECT)
获取系统信息。
wx.getSystemInfo({ success: function(res) { console.log(res.model) console.log(res.pixelRatio) console.log(res.windowWidth) console.log(res.windowHeight) console.log(res.language) console.log(res.version) console.log(res.platform) }})
completeFunction否接口调用结束的回调函数(调用成功、失败都会执行)success回调参数说明:
wx.getSystemInfoSync()
获取系统信息同步接口
try { var res = wx.getSystemInfoSync() console.log(res.model) console.log(res.pixelRatio) console.log(res.windowWidth) console.log(res.windowHeight) console.log(res.language) console.log(res.version) console.log(res.platform)} catch (e) { // Do something when catch error}
阅读全文
0 0
- 微信小程序8 位置与设备api
- 微信小程序位置API
- 微信小程序api调起微信提供的功能-网络、媒体、文件、数据存储、位置、设备、界面、开发接口
- 微信小程序 获取设备信息 API
- 微信小程序把玩(三十八)获取设备信息 API
- 微信小程序Ble设备连接与发送
- 位置与地图:定位获取设备的位置
- 微信小程序临时文件位置
- 微信小程序8 界面api
- 小程序文档整理之 -- API(位置)
- 微信小程序开发文档位置
- 小程序文档整理之 -- API(设备)
- 微信小程序 Image API
- 微信小程序 Audio API
- 微信小程序 Video API
- 微信小程序 Storage API
- 微信小程序 location API
- 微信小程序 navigation API
- 测试工具功能介绍
- offer
- LCA 入门
- vim:一些命令和选项 filetype, autocmd, map,tabstop等
- Offer
- 微信小程序8 位置与设备api
- String转int 非库函数 Java
- Java Jersey web service 总结
- vim:学习资料——把vim打造成 IDE
- ZooKeeper学习之zookeeper的ACL(AUTH)
- JDBC的使用
- http://doc.qt.io/qt-5/qtwidgets-gestures-imagegestures-example.html
- OpenGL视角LooAt及Perspective理解
- 【Leetcode】【python】Search Insert Position