PHP CURL根據詳細地址獲取騰訊地圖經緯度

 1 <?php
 2 
 3 
 4 $address = "廣東省廣州市天河區";
 5 $point = getPoint($address);
 6 
 7 var_dump($point);//輸出經緯度
 8 
 9 
10 /**
11  * 【根據詳細地址獲取經緯度】
12  *  20170920
13  *
14  * @param $address
15  * @return array
16  */
17 function getPoint($address){
18     $url = "http://apis.map.qq.com/jsapi?qt=geoc&addr={$address}}&key=6KLBZ-EW7CV-BVFPV-UUFU2-6STGE-G7BI7&output=jsonp&pf=jsapi&ref=jsapi&cb=qq.maps._svcb3.geocoder0";
19     $ch = curl_init($url);
20 
21     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//轉爲字符串,而不是直接輸出
22 
23     $wetContent = curl_exec($ch);
24 
25 
26     $data = iconv("GB18030", "UTF-8//IGNORE", $wetContent);
27 
28     $match = '/"pointx":"([\s\S]*?)",\s*?"pointy":"([\s\S]*?)"/';
29 
30     if(preg_match($match,$data,$rst)){
31         $arr = [
32             'longitude' => $rst[1],
33             'latitude' => $rst[2],
34         ];
35     }else{
36         $arr = [
37             'longitude' => '',
38             'latitude' => '',
39         ];
40     }
41 
42     curl_close($ch);
43     return $arr;
44 
45 
46 }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章