当前位置:网站首页>Small program WeChat positioning is not accurate
Small program WeChat positioning is not accurate
2022-07-29 22:15:00 【~Memories】
It is related to the WeChat positioning type!类型改为gcj02,加上属性isHighAccuracy为trueprecise positioning10m以内
wx.getLocation({
type: 'gcj02',
isHighAccuracy: true,//开启高精度定位
// 获取地理位置成功
success(res) {
if (callback) callback(res);
},
// 获取地理位置失败
fail() {
}
});
getLocation: function(callback, fail) {
let that = this;
wx.authorize({
scope: 'scope.userLocation',
// 授权-获取地理位置
success() {
// 获取地理位置
that.location(callback);
},
// 拒绝-获取地理位置
fail() {
// 获取用户当前设置
wx.getSetting({
// 获取用户当前设置-成功
success(res) {
// 没有授权-then request settings
if (!res.authSetting['scope.userLocation']) {
// Prompt for authorization
wx.showModal({
title: '请求授权当前位置',
content: '',
// 确认-打开设置
success: function(result) {
if (result.confirm) {
// 打开设置(Whether authorized or not,It will be executed after returningonShow)
wx.openSetting({
success(res) {
wx.getSetting({
success() {
if (!res
.authSetting[
'scope.userLocation'
]
) {
if (
fail
)
fail();
} else {
that.location(
callback
);
}
}
});
}
});
} else {
// Cancel Open Settings
if (fail) fail();
}
}
});
} else {
// 已经授权-Get the geographic location directly
that.location(callback);
}
}
});
}
});
},
参考链接:https://blog.csdn.net/abchhhxz/article/details/119697477
边栏推荐
猜你喜欢
![[ACTF2020 新生赛]Exec 1](/img/1e/a3c19d514207e6965d09c66b86e519.png)
[ACTF2020 新生赛]Exec 1

MySQL数据查询 - 简单查询

WeChat Mini Program 31 Subcontracting Mechanism

SwiftUI CoreData 教程之如何加速搜索速度

Come in now!!!Take you to know the basic data types of C language

Analysis of Crypto in Pi 2

小程序预览pdf

bright day

华为畅享50 Pro评测:HarmonyOS加持 更流畅更安全

Fully automated machine learning modeling!The effect hangs the primary alchemist!
随机推荐
分布式之基石: 可靠性——What a tangled web we weave
容器网络硬核技术内幕 (23) 权利,知识与责任
结合布林线理解现货白银走势图的方法
The Ministry of Human Resources and Social Security announced that "database operation administrator" has become a new occupation, and OceanBase participated in the formulation of occupational standar
VR直播营销需求增加,数据模块为我们铺路
Cooler Navigation helps you shop easily in shopping malls without confusion
The demand for VR live broadcast marketing is increasing, and the data module is paving the way for us
第3章业务功能开发(线索关联市场活动,插入数据并查询)
关于云计算的海量数据存储模型[通俗易懂]
赶紧进来!!!带你认识C语言基本数据类型
First thoughts on the first attempt to avoid killing without a file (Part 1)
数组和List互转
刚重装的win7系统不能上网(深度系统安装步骤)
The sword refers to Offer II 097. Number of subsequences
WeChat Mini Program 30 Customizing Templates and Obtaining User Login Credentials
Xshell 7 提示 “要继续使用此程序,您必须应用最新的更新或使用新版本”
三品牌下半年将带来多款新品,东风日产将迎来“产品大潮”
容器网络硬核技术内幕 (小结-下)
MySQL Data Query - Union Query
【AD】【持续更新ing】关于AD设计过程中一些小细节