当前位置:网站首页>微信小程序获取住户地区信息
微信小程序获取住户地区信息
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 - Coordinate Systems
- A detailed explanation of the general process and the latest research trends of map comparative learning (gnn+cl)
- Jenkins pipeline method (function) definition and call
- 2310. The number of bits is the sum of integers of K
- Transfer learning and domain adaptation
- C # image difference comparison: image subtraction (pointer method, high speed)
- Wxss template syntax
- Editor use of VI and VIM
- [reading notes] Figure comparative learning gnn+cl
- Summary of "reversal" problem in challenge Programming Competition
猜你喜欢
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
VS Code问题:长行的长度可通过 “editor.maxTokenizationLineLength“ 进行配置
Information and entropy, all you want to know is here
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
优先级队列(堆)
Can't find the activitymainbinding class? The pit I stepped on when I just learned databinding
牛顿迭代法(解非线性方程)
一次 Keepalived 高可用的事故,让我重学了一遍它
My experience from technology to product manager
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition
随机推荐
Nips2021 | new SOTA for node classification beyond graphcl, gnn+ comparative learning
Talking about label smoothing technology
2311. Longest binary subsequence less than or equal to K
2310. The number of bits is the sum of integers of K
项目实战 | Excel导出功能
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
Uni app implements global variables
驾驶证体检医院(114---2 挂对应的医院司机体检)
Generate confrontation network
Kotlin introductory notes (II) a brief introduction to kotlin functions
Composition of applet code
My experience from technology to product manager
[ManageEngine] how to make good use of the report function of OpManager
2311. 小于等于 K 的最长二进制子序列
编辑器-vi、vim的使用
VS Code问题:长行的长度可通过 “editor.maxTokenizationLineLength“ 进行配置
[beauty of algebra] solution method of linear equations ax=0
Priority queue (heap)
Alibaba's ten-year test brings you into the world of APP testing
牛顿迭代法(解非线性方程)