当前位置:网站首页>微信小程序获取住户地区信息
微信小程序获取住户地区信息
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
边栏推荐
- uni-app 实现全局变量
- Huber Loss
- [code practice] [stereo matching series] Classic ad census: (6) multi step parallax optimization
- scipy.misc.imread()
- LeetCode 31. 下一个排列
- RT thread kernel quick start, kernel implementation and application development learning with notes
- Wxss template syntax
- Progressive JPEG pictures and related
- Explain NN in pytorch in simple terms CrossEntropyLoss
- Nodejs modularization
猜你喜欢
牛顿迭代法(解非线性方程)
Svgo v3.9.0+
Blogger article navigation (classified, real-time update, permanent top)
Android 隐私沙盒开发者预览版 3: 隐私安全和个性化体验全都要
Nips2021 | new SOTA for node classification beyond graphcl, gnn+ comparative learning
An article takes you into the world of cookies, sessions, and tokens
Kotlin introductory notes (VII) data class and singleton class
Introduction Guide to stereo vision (1): coordinate system and camera parameters
Add discount recharge and discount shadow ticket plug-ins to the resource realization applet
Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
随机推荐
Android 隐私沙盒开发者预览版 3: 隐私安全和个性化体验全都要
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
Composition of applet code
Jenkins Pipeline 方法(函数)定义及调用
Talking about label smoothing technology
Blogger article navigation (classified, real-time update, permanent top)
Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]
Multiple linear regression (gradient descent method)
OpenGL - Model Loading
[code practice] [stereo matching series] Classic ad census: (5) scan line optimization
Applet customization component
我的一生.
Node collaboration and publishing
[technical school] spatial accuracy of binocular stereo vision system: accurate quantitative analysis
It's too difficult to use. Long articles plus pictures and texts will only be written in short articles in the future
C语言-从键盘输入数组二维数组a,将a中3×5矩阵中第3列的元素左移到第0列,第3列以后的每列元素行依次左移,原来左边的各列依次绕到右边
项目实战 | Excel导出功能
【组队 PK 赛】本周任务已开启 | 答题挑战,夯实商品详情知识
云计算技术热点
C # image difference comparison: image subtraction (pointer method, high speed)