// 引入SDK核心类--去官网下载qqmap-wx-jssdk.min.js
var QQMapWX = require('./static/js/qqmap-wx-jssdk.min.js');
/**
* 微信获得经纬度
*/
getLocation() {
let vm = this;
wx.getLocation({
type: 'wgs84',
success: function(res) {
var latitude = res.latitude
var longitude = res.longitude
var speed = res.speed
var accuracy = res.accuracy;
vm.getLocal(latitude, longitude)
},
fail: function(res) {
console.log('fail' + JSON.stringify(res))
}
})
},
/**
* 获取当前地理位置
*/
getLocal(latitude, longitude) {
let vm = this;
// 实例化API核心类
var qqmapsdk = new QQMapWX({
key: 'MOPBZ-2QSCW-OJZRG-R7QLR-AYVEV-2WF6B' // 必填
});
qqmapsdk.reverseGeocoder({
location: {
latitude: latitude,
longitude: longitude
},
get_poi: 1,
poi_options: 'policy=2;radius=3000;page_size=20;page_index=1',
success: function(res) {
//自己拿需要的东西
},
fail: function(res) {
console.log("解析失败");
},
});
},
/***
* 授权地理位置登录判断---在需要定位的页面调用这个方法
*/
getUserLocation() {
var vm = this;
wx.getSetting({
success: res => {
console.log("成功")
console.log(res.authSetting['scope.userLocation'])
if (res.authSetting['scope.userLocation'] != undefined && res.authSetting['scope.userLocation'] != true) {
wx.showModal({
title: '标题',
content: '您的位置信息将用于小程序位置接口的效果展示',
confirmColor: '#ee5002',
success: function(res) {
if (res.cancel) {
wx.showToast({
title: '拒绝授权',
icon: 'none',
duration: 1000
})
} else if (res.confirm) {
wx.openSetting({
success: function(dataAu) {
if (dataAu.authSetting["scope.userLocation"] == true) {
console.log(dataAu)
wx.showToast({
title: '授权成功',
icon: 'success',
duration: 1000
})
vm.getLocation()
} else {
wx.showToast({
title: '授权失败',
icon: 'none',
duration: 1000
})
}
}
})
}
}
})
} else if (res.authSetting['scope.userLocation'] == undefined) {
vm.getLocation()
} else {
vm.getLocation()
}
},
fail: (res) => {
console.log("失败")
}
})
},