Browse Source

测试定位功能

应县
yxq 1 year ago
parent
commit
80ec65bbba
1 changed files with 17 additions and 39 deletions
  1. +17
    -39
      Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/scanCode.vue

+ 17
- 39
Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/scanCode.vue View File

@@ -31,7 +31,7 @@
timestamp: success.timestamp, // 必填,生成签名的时间戳
nonceStr: success.noncestr, // 必填,生成签名的随机串
signature: success.certificate, // 必填,签名
jsApiList: ["scanQRCode","getLocation"] // 必填,需要使用的JS接口列表
jsApiList: ["scanQRCode"] // 必填,需要使用的JS接口列表
});
this.wxObject.ready(() => {
this.TOAST("扫码初始化成功")
@@ -45,49 +45,27 @@
},
scanCode(){
return new Promise((resolve)=>{
if(!this.wxObject||!this.wxObject.getLocation){
if(!this.wxObject||!this.wxObject.scanQRCode){
this.TOAST("无效方法")
resolve(false)
}else{
this.TOAST("正在定位...")
this.TOAST("正在调用扫码...")
}
this.wxObject.getLocation({
type: "gcj02", // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function (res) {
var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
var speed = res.speed; // 速度,以米/每秒计
var accuracy = res.accuracy; // 位置精度
console.log({latitude,longitude,speed,accuracy})
alert(latitude + '' + longitude)
},
fail:function(error){
this.TOAST("定位失败")
alert(error)
console.log(error)
}
this.wxObject.scanQRCode({
needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有
success: (res) => {
this.TOAST("方法调用成功")
var result = res.resultStr; // 当 needResult 为 1 时,扫码返回的结果
var resultArr = result.split(','); // 扫描结果以逗号分割数组
var codeContent = resultArr[resultArr.length - 1]; // 获取数组最后一个元素,也就是最终的内容
resolve({result:codeContent})
},
fail: (res) =>{
this.TOAST("调用扫码失败")
resolve(false)
}
});
// if(!this.wxObject||!this.wxObject.scanQRCode){
// this.TOAST("无效方法")
// resolve(false)
// }else{
// this.TOAST("正在调用扫码...")
// }
// this.wxObject.scanQRCode({
// needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
// scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有
// success: (res) => {
// this.TOAST("方法调用成功")
// var result = res.resultStr; // 当 needResult 为 1 时,扫码返回的结果
// var resultArr = result.split(','); // 扫描结果以逗号分割数组
// var codeContent = resultArr[resultArr.length - 1]; // 获取数组最后一个元素,也就是最终的内容
// resolve({result:codeContent})
// },
// fail: (res) =>{
// this.TOAST("调用扫码失败")
// resolve(false)
// }
// });
})
}
},


Loading…
Cancel
Save