当前位置:网站首页>Taro obtains longitude, latitude and city
Taro obtains longitude, latitude and city
2022-07-18 18:58:00 【Stavin Li】
app.config.js permissions
export default {
...,
permission: {
'scope.userLocation': {
desc: ' Need to get your location information and recommend suitable jobs for you '
}
},
...
};
import {
getSetting, authorize } from '@tarojs/taro';
/** * Baidu positioning * @returns */
const getMap = () => {
return new Promise((reslove, reject) => {
// https://github.com/baidumapapi/wxapp-jsapi/blob/master/src/bmap-wx.min.js
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 });
}
});
});
};
/** * View user authorization * @returns */
getSetting({
success: function (res) {
if (!res.authSetting['scope.userLocation']) {
authorize({
scope: 'scope.userLocation',
success: async () => {
console.log(' Authorized success ');
const {
location, city } = await getMap();
console.log(location, city)
},
fail(err) {
//err
}
});
} else {
getMap().then(({
location, city }) => {
console.log(location, city)
});
}
}
});
边栏推荐
- [Huang ah code] Introduction to MySQL - 3. I use select *, and the boss directly rushed me home by train, but I still bought a station ticket
- 自定义类型——结构体
- The principle and implementation of ring queue
- Let's customize the reflection system
- taro 获取经纬度及城市
- How does Huawei ENSP network implement VLAN configuration of switches?
- Learning path PHP -- post can't get the requested data
- 【C语言刷LeetCode】134. 加油站(M)
- Custom type - structure
- Software testing interview questions: briefly describe what is static testing, dynamic testing, black box testing, white box testing α Testing β Testing?
猜你喜欢
随机推荐
2022/7/15 每日一题(二分+dp+贪心思维)
【C语言刷LeetCode】134. 加油站(M)
Keywords some, option in rust
HCIP(7)
hcip实验作业(3)
HCIP(7)
事务隔离级别
Software testing interview questions: briefly describe what is static testing, dynamic testing, black box testing, white box testing α Testing β Testing?
Can optical fiber converter solves the long-distance networking problem of taihe'an tx3016a fire engine
Custom type - structure
树状数组
Series operations of function templates (detailed explanation)
2022 New Year blessing code interpretation (1)
Flink CEP - 复杂事件处理(Complex Event Processing)
Seventh note: machine level code representation of programs
go语言零知识证明gnark框架
多端口和单臂路由器互联VLAN实验
最少转机--图的广度优先遍历
Know JVM
LeetCode高频题:三个长度为N的无序数组A,B,C,求 A[i] + B[j] + C[k] = 64 的(i , j, k )的组合总数量







![[ CTF ]MISC flag](/img/f5/ef047a7026d577c661d3c20a2ff78b.png)