函数编写
getlocal: function() {
return new Promise((resolve, reject) => {
// var that = this
uni.getLocation({
type: 'gcj02', //返回可以用于uni.openLocation的经纬度,默认值为wgs84;可选值( 1.wgs84 返回 gps 坐标,2.gcj02 返回可用于 wx.openLocation 的坐标)
wgs84: false, // 传入 true 会返回高度信息,由于获取高度需要较高精确度,会减慢接口返回速度
sHighAccuracy: false, // 开启高精度定位
highAccuracyExpireTime: 3000,
success: function (res) {
console.log('成功获取位置信息',res)
},
fail: function (error) {
console.log('获取当前位置失败',error)
},
complete: function(com){
console.log('接口调用结束的回调函数(调用成功、失败都会执行)',com)
}
})
})
},
调用函数
onReady() {
//调用的函数放到onReady里面
this.getlocal()
},