微信公眾號開發(五)-- 獲取使用者位置
阿新 • • 發佈:2018-12-11
獲取jssdk
連結 裡面有寫
獲得使用者地理位置許可權
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script> <script> wx.config({ debug: false, appId: '<?php echo $signPackage["appId"]; ?>', timestamp: <?php echo $signPackage["timestamp"]; ?>, nonceStr: '<?php echo $signPackage["nonceStr"]; ?>', signature: '<?php echo $signPackage["signature"]; ?>', jsApiList: [ // 所有要呼叫的 API 都要加到這個列表中 'getLocation', ] }); 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.error(function(res){ alert("介面調取失敗") }); wx.getLocation({ success: function (res) { console.log(JSON.stringify(res)); }, cancel: function (res) { alert('使用者拒絕授權獲取地理位置'); } }); }); </script>