function isLeeWeiXin(){ var ua = window.navigator.userAgent.toLowerCase(); if(ua.match(/MicroMessenger/i) == 'micromessenger'){ return true; }else{ return false; } } if(isLeeWeiXin()){ wx.config({ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: 'wx570cb4ad2b4e7ef4', // 必填,公众号的唯一标识 timestamp: 1726586794, // 必填,生成签名的时间戳 nonceStr: 'bTwo74cbdklmmKyM', // 必填,生成签名的随机串 signature: '0b70d3c7590855a524244480dca22cfc2699ca39',// 必填,签名,见附录1 jsApiList: ['getLocation'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function(){ wx.checkJsApi({ jsApiList: [ 'getLocation' ], success: function (res) { // alert(JSON.stringify(res)); // alert(JSON.stringify(res.checkResult.getLocation)); if (res.checkResult.getLocation == false) { // alert('你的微信版本太低,不支持微信JS接口,请升级到最新的微信版本!'); return; } } }); wx.getLocation({ success: function (res) { var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90 var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。 /*var speed = res.speed; // 速度,以米/每秒计 var accuracy = res.accuracy; // 位置精度*/ // setCookie('lzhq_longitude',res.longitude); // setCookie('lzhq_latitude',res.latitude); //alert(res.latitude); //latitude = 42.008489; //longitude = 121.690063; //这里获取腾讯地图的API //将经纬度写入session $.get("/center/savelat.html",{'x':latitude,'y':longitude},function(d){}); }, cancel: function (res) { //alert('用户拒绝授权获取地理位置'); // delCookie('lzhq_longitude'); // delCookie('lzhq_latitude'); $.get("/center/savelat.html",{'x':0,'y':0},function(d){}); } }); }); }