小程序
小游戏
企业微信
微信支付
扫描小程序码分享
微信定位关闭的情况下,打开网页会提示获取地理位置,点击允许后,没有获取到地理位置,getLocation方法没有调用,刷新,返回上一页都没有作用
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
你好,你说的打开网页是指公众号还是小程序内呢?能否提供相关的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)?
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
打开公众号
var u = navigator.userAgent;
var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
if (isiOS == true) {
if (localStorage.getItem("pagerole") == "visittime") {
var urldata = global_.getRandColor() + "/history";
} else {
var urldata = global_.getRandColor() + "/functionmap";
}
var urldata = window.location.href;
let that = this;
let condition = {
url: urldata
};
let promise = api.queryaddresss(condition);
promise.then(function(response) {
if (response.status === 200 && response.data.success === true) {
that.wxConfig = response.data.datas;
wx.config({
debug: true,
appId: globalConfig.CORPID,
timestamp: that.wxConfig.signTime,
nonceStr: that.wxConfig.nonceStr,
signature: that.wxConfig.signConfig,
jsApiList: [
// 所有要调用的 API 都要加到这个列表中
"checkJsApi",
"getLocation",
"openLocation",
"chooseImage",
"uploadImage",
"downloadImage"
]
});
wx.ready(function() {
wx.getLocation({
type: "gcj02", // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function(res) {
that.isaddress = false;
that.latitude = Number(res.latitude); // 纬度,浮点数,范围为90 ~ -90
that.longitude = Number(res.longitude); // 经度,浮点数,范围为180 ~ -180。
that.speed = res.speed; // 速度,以米/每秒计
that.accuracy = res.accuracy; // 位置精度
//用高德地图通过经纬度确定具体地址
// var map = new AMap.Map("app", {
// resizeEnable: true,
// zoom: 18
// }),
let lnglatXY = [that.longitude, that.latitude]; //已知点坐标
function regeocoder() {
//逆地理编码
var geocoder = new AMap.Geocoder({
radius: 1000,
extensions: "all"
geocoder.getAddress(lnglatXY, function(status, result) {
if (status === "complete" && result.info === "OK") {
geocoder_CallBack(result);
var marker = new AMap.Marker({
//加点
map: map,
position: lnglatXY
map.setFitView();
function geocoder_CallBack(data) {
var address = data.regeocode.formattedAddress; //返回地址描述
that.myaddress = address;
// console.log(that.myaddress)
// document.getElementById("result").innerHTML = address;
regeocoder();
},
cancel: function(res) {
console.log("用户拒绝授权");
that.isaddress = true;
fail: function () {
alert("定位关闭了")
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
你好,你说的打开网页是指公众号还是小程序内呢?能否提供相关的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)?
打开公众号
var u = navigator.userAgent;
var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
if (isiOS == true) {
if (localStorage.getItem("pagerole") == "visittime") {
var urldata = global_.getRandColor() + "/history";
} else {
var urldata = global_.getRandColor() + "/functionmap";
}
} else {
var urldata = window.location.href;
}
let that = this;
let condition = {
url: urldata
};
let promise = api.queryaddresss(condition);
promise.then(function(response) {
if (response.status === 200 && response.data.success === true) {
that.wxConfig = response.data.datas;
wx.config({
debug: true,
appId: globalConfig.CORPID,
timestamp: that.wxConfig.signTime,
nonceStr: that.wxConfig.nonceStr,
signature: that.wxConfig.signConfig,
jsApiList: [
// 所有要调用的 API 都要加到这个列表中
"checkJsApi",
"getLocation",
"openLocation",
"chooseImage",
"uploadImage",
"downloadImage"
]
});
wx.ready(function() {
wx.getLocation({
type: "gcj02", // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function(res) {
that.isaddress = false;
that.latitude = Number(res.latitude); // 纬度,浮点数,范围为90 ~ -90
that.longitude = Number(res.longitude); // 经度,浮点数,范围为180 ~ -180。
that.speed = res.speed; // 速度,以米/每秒计
that.accuracy = res.accuracy; // 位置精度
//用高德地图通过经纬度确定具体地址
// var map = new AMap.Map("app", {
// resizeEnable: true,
// zoom: 18
// }),
let lnglatXY = [that.longitude, that.latitude]; //已知点坐标
function regeocoder() {
//逆地理编码
var geocoder = new AMap.Geocoder({
radius: 1000,
extensions: "all"
});
geocoder.getAddress(lnglatXY, function(status, result) {
if (status === "complete" && result.info === "OK") {
geocoder_CallBack(result);
}
});
var marker = new AMap.Marker({
//加点
map: map,
position: lnglatXY
});
map.setFitView();
}
function geocoder_CallBack(data) {
var address = data.regeocode.formattedAddress; //返回地址描述
that.myaddress = address;
// console.log(that.myaddress)
// document.getElementById("result").innerHTML = address;
}
regeocoder();
},
cancel: function(res) {
console.log("用户拒绝授权");
that.isaddress = true;
},
fail: function () {
alert("定位关闭了")
}
});
});
}
});