当前位置:网站首页>微信小程序获取住户地区信息
微信小程序获取住户地区信息
2022-07-05 09:21:00 【.translucent】
微信小程序获取住户地区信息
微信小程序获取住户地区信息
1.现在app.js里面配置如下
{
//向用户申请获取授权
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
}
}
2.在所需要获取的地区调用微信api
wx.getLocation({
type: 'wgs84',
success (res) {
const latitude = res.latitude
const longitude = res.longitude
const speed = res.speed
const accuracy = res.accuracy
}
})
//res返回如下字段
{
accuracy: 65;
errMsg: "getLocation:ok";
horizontalAccuracy: 65;
latitude: 30.25961; // 纬度,范围为 -90~90,负数表示南纬
longitude: 120.13026; // 经度,范围为 -180~180,负数表示西经
speed: -1;
verticalAccuracy: 65;
}
3.通过获取用户的api来获取用户的地址
//获取用户的ip地址
const getposition = () =>{
const params = {
//请求地址来获取用户ip
url:'https://pv.sohu.com/cityjson?ie=utf-8'
}
return request(params)
}
//getipconfig
//调用请求
const res = await getposition()
const m = JSON.parse(res.data.match(/.*(\{[^\}]+\}).*/)[1] || '{}')
//获取到ip
console.log('ip =>', m.cip, m)
通过IP地址来查询所用用户的地址
get请求http://ip-api.com/json/ip
http://ip-api.com/json/36.143.40.237
边栏推荐
猜你喜欢

OpenGL - Lighting

Nips2021 | new SOTA for node classification beyond graphcl, gnn+ comparative learning

RT thread kernel quick start, kernel implementation and application development learning with notes
![Introduction Guide to stereo vision (4): DLT direct linear transformation of camera calibration [recommended collection]](/img/ed/0483c529db2af5b16b18e43713d1d8.jpg)
Introduction Guide to stereo vision (4): DLT direct linear transformation of camera calibration [recommended collection]
![Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]](/img/7d/e7370e757c18b3dbb47e633703c346.jpg)
Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]

信息与熵,你想知道的都在这里了

Nodemon installation and use

What is a firewall? Explanation of basic knowledge of firewall

High performance spark_ Transformation performance

C语言-从键盘输入数组二维数组a,将a中3×5矩阵中第3列的元素左移到第0列,第3列以后的每列元素行依次左移,原来左边的各列依次绕到右边
随机推荐
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition
一次 Keepalived 高可用的事故,让我重学了一遍它
[beauty of algebra] solution method of linear equations ax=0
2309. The best English letters with both upper and lower case
Nips2021 | new SOTA for node classification beyond graphcl, gnn+ comparative learning
Summary and Reflection on issues related to seq2seq, attention and transformer in hands-on deep learning
Solution to the problem of the 10th Programming Competition (synchronized competition) of Harbin University of technology "Colin Minglun Cup"
OpenGL - Coordinate Systems
Luo Gu p3177 tree coloring [deeply understand the cycle sequence of knapsack on tree]
Mengxin summary of LCs (longest identical subsequence) topics
520 diamond Championship 7-4 7-7 solution
My life
Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
Can't find the activitymainbinding class? The pit I stepped on when I just learned databinding
Blogger article navigation (classified, real-time update, permanent top)
阿里云发送短信验证码
2309. 兼具大小写的最好英文字母
阿里十年测试带你走进APP测试的世界
Introduction Guide to stereo vision (4): DLT direct linear transformation of camera calibration [recommended collection]
Summary of "reversal" problem in challenge Programming Competition