获取位置
获取当前的地理位置、速度。当用户离开小程序后,此接口无法调用;当用户点击“显示在聊天顶部”时,此接口可继续调用。
wx.getLocation(object)
<view class="container"> <button bindtap='getLocation'>获取位置</button> <view wx:if="{{latitude !=''}}"> <view>纬度:{{latitude}}</view> <view>经度:{{longitude}}</view> <view>速度:{{speed}}</view> <view>位置的精确度:{{accuracy}}</view> <view>高度:{{altitude}}</view> <view>垂直精度:{{accuracy}}</view> <view>水平精度:{{accuracy}}</view> </view> </view>
//index.js //获取应用实例 const app = getApp() Page({ data: { latitude: '', longitude: '', speed: '', accuracy: '', altitude:'', verticalAccuracy: '', horizontalAccuracy:'' }, onLoad: function () { }, getLocation:function(){ var _this=this; wx.getLocation({ type: 'wgs84', success: function (res) { var latitude = res.latitude var longitude = res.longitude var speed = res.speed var accuracy = res.accuracy var altitude = res.altitude var verticalAccuracy = res.verticalAccuracy var horizontalAccuracy = res.horizontalAccuracy _this.setData({ latitude: latitude, longitude: longitude, speed: speed, accuracy: accuracy, altitude: altitude, verticalAccuracy: verticalAccuracy, horizontalAccuracy: horizontalAccuracy }) } }) } })
打开地图选择位置
wx.chooseLocation(OBJECT)
打开地图选择位置。
需要用户授权 scope.userLocation
wx.chooseLocation(object)
<view class="container"> <button bindtap='getLocation'>打开地图选择位置</button> <view wx:if="{{address !=''}}"> <view>位置名称:{{name}}</view> <view>详细地址:{{address}}</view> <view>纬度:{{latitude}}</view> <view>经度:{{longitude}}</view> </view> </view>
//index.js //获取应用实例 const app = getApp() Page({ data: { name: '', address: '', latitude: '', longitude: '' }, onLoad: function () { }, getLocation:function(){ var _this=this; wx.chooseLocation({ success: function (res) { var name = res.name var address = res.address var latitude = res.latitude var longitude = res.longitude _this.setData({ name: name, address: address, latitude: latitude, longitude: longitude }) } }) } })
wx.openLocation(OBJECT)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 魏新雨《为你祈祷+新歌精逊2CD[WAV]
- 影心、明萨拉你选哪个?国外美女COS《博德3》
- 澳洲女子骑车跌入“自杀树”丛 疼痛持续9个月崩溃
- 育碧公布2024“她创力”计划:为女性游戏人提供辅导
- 刘美君.2017-千色·30总选3CD【环球】【WAV+CUE】
- 群星.2022-星河长明电视原声带【乐有奇思】【FLAC分轨】
- 陈淑桦.1995-淑桦盛开Forever【滚石】【WAV+CUE】
- 《再来一张》评测:出师成败皆系“赌”
- 《银河汉堡店》测评:我是银河走菜王!
- 《末日地带2》评测:酣畅淋漓的“和面”之旅
- 萧煌奇《没事的》[320K/MP3][96.22MB]
- 萧煌奇《没事的》[FLAC/分轨][263.38MB]
- 群星《音你而来 第6期》[320K/MP3][90.61MB]
- 交错战线爬塔攻略一览
- 战锤40K星际战士2全近战武器使用教学|近战武器连招表