<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 1.首先簡單封裝一個發送curl的方法 ```php /** * 發送curl網絡請求 * @param $url string 請求地址 * @param $type int 0:get 1:post * @param $data array post方式提交的數據 * @return array|json */ function doCurl($url, $type=0, $data=[]){ //初始化curl $ch = curl_init(); //curl參數設置 curl_setopt($ch, CURLOPT_URL, $url);//curl請求的url curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//設置放回值,不輸出結果 curl_setopt($ch, CURLOPT_HEADER, 0);//不緩存響應頭 //如果是post請求 if($type==1){ curl_setopt($ch, CURLOPT_POST, 1);//設置post方式 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//post方式提交的數組 } //執行curl發送請求 $output = curl_exec($ch); //釋放當前curl句柄 curl_close($ch); //放回請求到的數據 return $output; } ``` ## 2.extend中新建Map.php類,封裝百度地圖api接口 ```php <?php /** * 百度地圖api接口封裝 */ use think\Config; class Map{ //通過地址獲取經緯度信息(地理編碼) public static function getLngLat($address) { if($address == ""){ return ""; } //http://api.map.baidu.com/geocoding/v3/?address=北京市海淀區上地十街10號&output=json&ak=您的ak&callback=showLocation //GET請求 $data = [ 'address' => $address, 'output' => 'json', 'ak' => Config::get('map.ak'), 'callback' => 'showLocation' ]; $query = http_build_query($data);//轉化為url后的參數 $url = Config::get('map.baidu_map_url').Config::get('map.geocoding').'?'.$query; //發送網絡請求: 1.file_get_content 2.curl //$result = file_get_contents($url); $result = doCurl($url); return $result; } /**通過經緯度或地址 去生成靜態地圖 (靜態圖) * http://api.map.baidu.com/staticimage/v2?ak=你的ak&mcode=666666&center=116.403874,39.914888&width=300&height=200&zoom=11 **/ public static function staticImage($center) { if($center == ""){ return ""; } $data = [ 'ak' => Config::get('map.ak'), 'width' => config('map.width'), 'height' => config('map.height'), 'center' => $center, 'markers' => $center, 'staticimage' => config('map.staticimage') ]; $query = http_build_query($data); $url = Config::get('map.baidu_map_url').Config::get('map.staticimage').'?'.$query; $result = doCurl($url); return $result; } } ``` ## 3.配置map的信息寫在了extra下的map.php中 ```php <?php //百度地圖api配置 return [ 'ak' => '你的百度ak', 'baidu_map_url' => 'http://api.map.baidu.com/', 'geocoding' => 'geocoding/v3/', 'width' => 400, 'height' => 300, 'staticimage' => 'staticimage/v2' ]; ``` ## 4.控制器中調用 已admin/index控制器為例 ```php <?php namespace app\admin\controller; use think\Controller; class Index extends Controller { .... //測試靜態圖生成 public function map() { return \Map::staticImage('廣州市天河區車陂大塘后街10號'); } //測試路由 public function test() { return \Map::getLngLat('廣州市天河區車陂地鐵C出口'); } } ``` html中展示靜態圖 ```html <img style="margin:20px" width="280" height="140" src="{:url('/admin/index/map')}"/> ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看