html52.com
我爱小程序-开发者交流社区

公众号网页微信获取地理位置 getlocation fail

问题模块 框架类型 终端类型 操作系统 微信版本 基础库版本
框架 小程序 客户端 jweixin-1.0.0.js jweixin-1.0.0.js



网页获取地理位置web开发工具无问题,有的手机可以,有的不可以,不可以的报错getlocation fail

qq:1163284857,麻烦各位大神看看

function SetUserLoad(JsonData) {
    console.log(JsonData);
    wx.config({
        debug:  true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
        appId: JsonData.appId, // 必填,公众号的唯一标识
        timestamp: JsonData.timestamp, // 必填,生成签名的时间戳
        nonceStr: JsonData.noncestr, // 必填,生成签名的随机串
        signature: JsonData.signature,// 必填,签名,见附录1
        jsApiList: ['checkJsApi', 'openLocation','getLocation',] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
    });
    wx.ready(function(){
        alert("成功");
        getjsJW();
    });
    wx.error(function (res) {
        alert("失败");
        console.log(res);
        localStorage.setItem("JSAccessToken", "");
        localStorage.setItem("jsapi_ticket", "");
        // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
    });
 
}
function getjsJW() {
    //wx.checkJsApi({
    //    jsApiList: ['getLocation'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
    //    success: function (res) {
    //        alert(JSON.stringify(res))
    //        // 以键值对的形式返回,可用的api值true,不可用为false
    //        // 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
    //    }
    //});
    wx.getLocation({
        type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
        success: function (res) {
            var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
            var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
            var speed = res.speed; // 速度,以米/每秒计
            var accuracy = res.accuracy; // 位置精度
            localStorage.setItem("longitude", longitude);
            localStorage.setItem("latitude", latitude);
            alert(longitude + "维度:  " + latitude);
        },
        cancel: function (res) {
            alert(JSON.stringify(res))
            alert('用户拒绝授权获取地理位置');
        },
        fail: function (res) {
            alert(JSON.stringify(res))
            alert('失败方法');
        }
    });
}

qq:1163284857

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付