当前位置:网站首页>微信小程序获取住户地区信息
微信小程序获取住户地区信息
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
边栏推荐
- C # compare the differences between the two images
- STM32 simple multi-level menu (array table lookup method)
- Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
- 交通运输部、教育部:广泛开展水上交通安全宣传和防溺水安全提醒
- Global configuration tabbar
- 2309. The best English letters with both upper and lower case
- Transfer learning and domain adaptation
- 22-07-04 西安 尚好房-项目经验总结(01)
- C language - input array two-dimensional array a from the keyboard, and put 3 in a × 5. The elements in the third column of the matrix are moved to the left to the 0 column, and the element rows in ea
- 混淆矩阵(Confusion Matrix)
猜你喜欢

Editor use of VI and VIM

Attention is all you need
![Rebuild my 3D world [open source] [serialization-1]](/img/74/b6253845b43bc18f425d57695fba7c.jpg)
Rebuild my 3D world [open source] [serialization-1]

What is a firewall? Explanation of basic knowledge of firewall

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

OpenGL - Lighting

Using request headers to develop multi terminal applications

Kotlin introductory notes (V) classes and objects, inheritance, constructors

An article takes you into the world of cookies, sessions, and tokens

Svg optimization by svgo
随机推荐
OpenGL - Lighting
Figure neural network + comparative learning, where to go next?
Luo Gu p3177 tree coloring [deeply understand the cycle sequence of knapsack on tree]
Kotlin introductory notes (I) kotlin variables and non variables
Rebuild my 3D world [open source] [serialization-2]
Android 隐私沙盒开发者预览版 3: 隐私安全和个性化体验全都要
Introduction Guide to stereo vision (1): coordinate system and camera parameters
[beauty of algebra] singular value decomposition (SVD) and its application to linear least squares solution ax=b
Golang foundation -- map, array and slice store different types of data
OpenGL - Model Loading
LeetCode 556. 下一个更大元素 III
notepad++
NIPS2021 | 超越GraphCL,GNN+对比学习的节点分类新SOTA
Using request headers to develop multi terminal applications
np.allclose
Solution to the problem of the 10th Programming Competition (synchronized competition) of Harbin University of technology "Colin Minglun Cup"
Composition of applet code
编辑器-vi、vim的使用
Alibaba cloud sends SMS verification code
Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method