微信 騰訊地圖 api 坐標 網頁 獲取地理位置 key


 

<script>

wx.config({  
    debug: false, // 開啟調試模式,調用的所有api的返回值會在客戶端alert出來,若要查看傳入的參數,可以在pc端打開,參數信息會通過log打出,僅在pc端時才會打印。  
    appId: '{$wx_config.appId}', 
    timestamp: '{$wx_config.timestamp}', 
    nonceStr: '{$wx_config.nonceStr}', 
    signature: '{$wx_config.signature}',
    jsApiList: ['checkJsApi',
                'chooseImage',
                'previewImage',
                 'uploadImage',
                 'downloadImage',
                  'getNetworkType',//網絡狀態接口
                  'openLocation',//使用微信內置地圖查看地理位置接口
                  'getLocation' //獲取地理位置接口
               ] // 必填,需要使用的JS接口列表,所有JS接口列表見附錄2  
});


function get2set2addr(latitude, longitude){

    $.ajax({
        url:"{:url('addr/ajax_addr')}",
        data:{'latitude':latitude, 'longitude':longitude},
        dataType:"json",
        type:"post",
        success:function(r){
            if(r.check==1){
                $('#addr').val(r.msg);
                
            }else{
                alert(r.msg); 
            }

        }
    })
}

function get_la_lo(){
    wx.getLocation({
        type: 'wgs84', // 默認為wgs84的gps坐標,如果要返回直接給openLocation用的火星坐標,可傳入'gcj02'
        success: function (res) {
      
        var latitude = res.latitude; // 緯度,浮點數,范圍為90 ~ -90
        var longitude = res.longitude; // 經度,浮點數,范圍為180 ~ -180。

        //alert(JSON.stringify(res));

        get2set2addr(latitude, longitude);
        
      },

      cancel: function (res) {
        alert('用戶拒絕授權,無法獲取地理位置');
      }

    });     
}

               
wx.ready(function () { 

// 7 地理位置接口 開始
  // 7.1 查看地理位置

$("#openLocation").click(function(){  
    wx.openLocation({
      latitude: 23.099994,
      longitude: 113.324520,
      name: 'TIT 創意園',
      address: '廣州市海珠區新港中路 397 號',
      scale: 14,
      infoUrl: 'http://weixin.qq.com'
    });
});


  // 7.2 獲取當前地理位置

$("#addr").click(function(){  

    get_la_lo();

}); 
// 7 地理位置接口 結束              
               


});
</script>

 

    public function ajax_addr()
    {
        if (request()->isAjax()) {//ajax latitude, longitude

            $d = $this->request->param();

            $r = https_request("http://apis.map.qq.com/ws/geocoder/v1/?location=".$d['latitude'].",".$d['longitude']."&key=F2GBZ-SREWQ-A3K56-GSLK5-ELOHS-PRB2X&get_poi=1");

            if(!$r['result']['address']){

                exit( json_encode(['check'=>0, 'msg'=>'廣東省深圳市']) );
            
            }else{

                exit( json_encode(['check'=>1, 'msg'=>$r['result']['address']]) );
            }

        }
    }

 


免責聲明!

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



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