安卓机 wx.getLocation没反应
发布于 5 年前 作者 mchang 14772 次浏览 来自 问答
wx.config({
                debug: true, // 因为在手机上测试没法打印,当debug为true时,所有的返回值都会在手机上alert出来
                appId: sdkSign.appId, // 必填,公众号唯一标识
                timestamp: sdkSign.timestamp, // 必填,生成签名的时间戳
                nonceStr: sdkSign.nonceStr, // 必填,生成签名的随机串
                signature: sdkSign.signature,// 必填,签名
                jsApiList: ['getLocation',] // 必填,需要调用的接口列表,本需求里只是获取位置信息,具体的接口名称查阅js-sdk文档
            });
            //获取地理位置
            wx.ready(function(){
                wx.getLocation({
                    type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
                    success: function (res) {
                        var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
                        var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
                        console.log('经度:'+longitude);
                        console.log('纬度:'+latitude);
                        getLocationBylatlng(latitude, longitude);
                    },
                    cancel: function (res) {
                        alertMsg("定位失败", 2);
                    },
                    fail: function(res){
                        alertMsg("定位失败", 2);
                    }
                });
            });
1 回复

您好,请在complete里面加日志,确定消息走到了这里。

如果还是有问题,请提供代码片段。

回到顶部