var bmap = require('bmap-wx.min.js')
// 百度地图API的使用
onLoad(options) {
var that = this
var BMAP = new bmap.BMapWX({
ak: ''
})
wx.getLocation({
type: 'wgs84',
success(res) {
that.setData({
latitude: res.latitude,
longitude: res.longitude
})
BMAP.regeocoding({
location: that.data.latitude + ',' + that.data.longitude,
success: function(res) {
const provinceAddress = res.originalData.result.addressComponent.province.replace('省', '')
const cityAddress = res.originalData.result.addressComponent.city.replace('市', '')
if (cityAddress) {
that.setData({
//页面渲染
})
that.getStoresList(cityAddress)
} else {
wx.showToast({
title: '请检查位置服务是否开启',
icon: 'none'
})
}
},
fail: function() {
wx.showToast({
title: '请检查位置服务是否开启!',
icon: 'none'
})
}
})
},
fail(e) {
wx.showModal({
title: '获取位置信息失败',
content: '获取位置权限失败, 请点击授权位置权限按钮,并在下一个页面赋予获取位置权限',
cancelText: '返回上页',
confirmText: '确定',
success(e) {
if (e.confirm === true) {
try {
wx.openSetting({})
} catch (e) {
that.setData({
//页面渲染
})
}
} else {
wx.navigateBack({})
}
},
fail(e) {
console.log(e);
}
})
},
})
},
微信小程序逆向定位解析+检查定位是否开启弹窗——百度实例
最新推荐文章于 2024-03-23 09:41:13 发布