taro 获取经纬度及城市

网友投稿 743 2022-11-16

taro 获取经纬度及城市

taro 获取经纬度及城市

app.config.js 权限设置

export default { ..., permission: { 'scope.userLocation': { desc: '需要获取您的位置信息为您推荐合适的工作岗位' } }, ...};

import { getSetting, authorize } from '@tarojs/taro';/** * 百度定位 * @returns */const getMap = () => { return new Promise((reslove,) => { // const bmap = require('@/assets/js/bmap-wx.min.js'); const BMap = new bmap.BMapWX({ ak: '' }); BMap.regeocoding({ fail: (data) => { reject(data); }, success: (data) => { const { originalData: { result: { location, addressComponent: { city } } } } = data; reslove({ location, city }); } }); });};/** * 查看用户授权 * @returns */getSetting({ success: function (res) { if (!res.authSetting['scope.userLocation']) { authorize({ scope: 'scope.userLocation', success: async () => { console.log('授权成功'); const { location, city } = await getMap(); console.log(location, city) }, fail(err) { //err } }); } else { getMap().then(({ location, city }) => { console.log(location, city) }); } }});

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:spring-boot test 使用screw 生成数据库文档
下一篇:算法题:剑指 Offer 45. 把数组排成最小的数 时空10ms(题目+思路+代码+注释)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~