获取位置获取当前的地理位置、速度。当用户离开小程序后,此接口无法调用;当用户点击“显示在聊天顶部”时,此接口可继续调用。
wx.getLocation(object)
?123456789101112?12345678910111213141516171819202122232425262728293031323334353637383940 //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 }) } }) }}) 纬度:{{latitude}} 经度:{{longitude}} 速度:{{speed}} 位置的精确度:{{accuracy}} 高度:{{altitude}} 垂直精度:{{accuracy}} 水平精度:{{accuracy}}
打开地图选择位置
wx.chooseLocation(OBJECT)
打开地图选择位置。 需要用户授权 scope.userLocation
wx.chooseLocation(object)?123456789?123456789101112131415161718192021222324252627282930 //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 addres 位置名称:{{name}} 详细地址:{{address}} 纬度:{{latitude}} 经度:{{longitude}}