<script type="text/javascript"> wx.config(jssdkconfig); require(['jquery', 'util'], function($, util){ var latitude; var longitude; var speed; var accuracy; wx.ready(function () { //test(); wx.onMenuShareAppMessage(sharedata); wx.onMenuShareTimeline(sharedata); wx.onMenuShareQQ(sharedata); wx.onMenuShareWeibo(sharedata); wx.getLocation({ type: 'wgs84', // 默認為wgs84的gps坐標,如果要返回直接給openLocation用的火星坐標,可傳入'gcj02' success: function (res) { latitude = res.latitude; // 緯度,浮點數,范圍為90 ~ -90 longitude = res.longitude; // 經度,浮點數,范圍為180 ~ -180。 speed = res.speed; // 速度,以米/每秒計 accuracy = res.accuracy; // 位置精度 alert('緯度:'+latitude+'經度:'+longitude+'速度:'+speed+'精度:'+accuracy); }, cancel: function (res) { alert('用戶拒絕授權獲取地理位置'); aWeixinJSBridge.call('closeWindow'); } }); }); }); </script>
這是針對微擎的html頁面的js代碼