微信公眾號,獲取定位


<script type="text/javascript" src="/js/jquery.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript">
//配置信息驗證接口
wx.config({
  debug: false,
  appId: '{$wx.appId}',
  timestamp: '{$wx.timestamp}',
  nonceStr: '{$wx.nonceStr}',
  signature: '{$wx.signature}',
  jsApiList: [
    // 所有要調用的 API 都要加到這個列表中
    'checkJsApi',
    'openLocation',
    'getLocation'
   ]
      });
//驗證之后進入該函數,所有需要加載頁面時調用的接口都必須寫在該里面
wx.ready(function () {
//基礎接口判斷當前客戶端版本是否支持指定JS接口
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。
	//alert("bbbbbbb");
	$.ajax({
		url : 'ajax.php?act=shoplist',
		data:{latitude:latitude,longitude:longitude},
		cache : false,
		async : true,
		type : "POST",
		dataType : 'text',
		success : function (result){
			console.log("111111");
			//alert(result);
		}
	});
  },
  cancel: function (res) {
  	alert("111111111");
  }
        });
      });
</script>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM