1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 微信端H5使用百度地图定位获取当前位置安卓定位不准

微信端H5使用百度地图定位获取当前位置安卓定位不准

时间:2022-11-08 13:49:31

相关推荐

微信端H5使用百度地图定位获取当前位置安卓定位不准

微信端H5使用百度地图定位获取当前位置安卓定位不准的问题解决如下:

使用微信端定位,签名方法看微信接口文档:

<script type="text/javascript">$.ajax({type : "post",url : "../user/sign.vc",data : {"url" : location.href.split('#')[0]},dataType : "json",success : function(data) {wx.config({ debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: data.appId, // 必填,公众号的唯一标识timestamp: data.timestamp, // 必填,生成签名的时间戳nonceStr: data.nonceStr, // 必填,生成签名的随机串signature: data.signature,// 必填,签名,见附录1jsApiList: ['checkJsApi','openLocation','getLocation'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function () {wx.checkJsApi({jsApiList: ['getLocation'],success: function (res) {if (res.checkResult.getLocation == false) {alert('你的微信版本太低,不支持微信JS接口,请升级到最新的微信版本!');return;}}});wx.error(function (res) {alert(res.errMsg);});});}});</script>`

传入坐标实现公交导航

function getMap(pointLng,pointLat,site) {wx.getLocation({type: 'wgs84', success: function (res) {var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。//坐标转换完之后的回调函数translateCallback = function (data){if(data.status === 0) {map.centerAndZoom(data.points[0], 13);map.enableScrollWheelZoom(true); var p1 = data.points[0];var p2 = new BMap.Point(pointLng,pointLat);var transit = new BMap.TransitRoute(map, {renderOptions: {map: map, panel: "r-result"},onResultsHtmlSet : function(){$("#r-result").show()}});transit.search(p1, p2);}}var ggPoint = new BMap.Point(longitude,latitude);var convertor = new BMap.Convertor();var pointArr = [];pointArr.push(ggPoint);convertor.translate(pointArr, 1, 5, translateCallback)},cancel: function (res) {alert('用户拒绝授权获取地理位置');},fail:function(){alert("用户不允许获取地理位置");}});}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。