{ "status": 0, "message": "ok", "result": [{ "name": "天安门", "location": { "lat": 39.915526, "lng": 116.403847 }, "uid": "65e1ee886c885190f60e77ff", "province": "北京市", "city": "北京市", "district": "东城区", "business": "", "cityid": "131" }, { "name": "天安门广场", "location": { "lat": 39.909652, "lng": 116.404177 }, "uid": "c9b5fb91d49345bc5d0d0262", "province": "北京市", "city": "北京市", "district": "东城区", "business": "", "cityid": "131" }, { "name": "天安门东-地铁站", "location": { "lat": 39.91408, "lng": 116.407851 }, "uid": "940aeb3c98d5a0218a2fb5de", "province": "北京市", "city": "北京市", "district": "东城区", "business": "", "cityid": "131" }, { "name": "天安门广场-国旗", "location": { "lat": 39.91328, "lng": 116.403931 }, "uid": "4ae2adcf574bcd2b38221c66", "province": "北京市", "city": "北京市", "district": "东城区", "business": "", "cityid": "131" }, { "name": "天安门西-地铁站", "location": { "lat": 39.913776, "lng": 116.39805 }, "uid": "002975204d3b1e9b9968b4de", "province": "北京市", "city": "北京市", "district": "西城区", "business": "", "cityid": "131" }, { "name": "天安门-华表", "location": { "lat": 39.91433, "lng": 116.404413 }, "uid": "3ff8be14bf465f3682288ac1", "province": "北京市", "city": "北京市", "district": "东城区", "business": "", "cityid": "131" }, { "name": "天安门东-公交车站", "location": { "lat": 39.914086, "lng": 116.408016 }, "uid": "e1ee3a5e7be676c8213bf257", "province": "北京市", "city": "北京市", "district": "东城区", "business": "", "cityid": "131" }, { "name": "天安门西-公交车站", "location": { "lat": 39.913723, "lng": 116.398056 }, "uid": "a8e23c622c11486eae045714", "province": "北京市", "city": "北京市", "district": "西城区", "business": "", "cityid": "131" }, { "name": "天安门-出口", "location": { "lat": 39.91543, "lng": 116.404241 }, "uid": "e93b3a20e96f63d55cd4fe95", "province": "北京市", "city": "北京市", "district": "东城区", "business": "", "cityid": "131" }, { "name": "天安门广场-出入口", "location": { "lat": 39.911425, "lng": 116.402508 }, "uid": "797c4f6023068d0ceedfcaf9", "province": "北京市", "city": "北京市", "district": "东城区", "business": "", "cityid": "131" } ] }
<?php /** * Created by PhpStorm. * User: FZS * Time: 2019/9/3 23:10 */ //---------------------------------- // 地点输入提示 调用类 //---------------------------------- class freeApi{ private $ak; private $apiUrl; public function __construct($ak){ $this->ak = $ak; $this->apiUrl = 'http://api.map.baidu.com/place/v2/suggestion?query=天安门®ion=北京&city_limit=true&output=json&ak='.$this->ak; } /** * 获取结果 * @return array */ public function getResult(){ return $this->freeApiCurl($this->apiUrl); } /** * 请求接口返回内容 * @param string $url [请求的URL地址] * @param string $params [请求的参数] * @param int $ipost [是否采用POST形式] * @return string */ public function freeApiCurl($url,$params=false,$ispost=0){ $ch = curl_init(); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); curl_setopt( $ch, CURLOPT_USERAGENT , 'chuanshuoapi' ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 ); curl_setopt( $ch, CURLOPT_TIMEOUT , 60); curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true ); if( $ispost ) { curl_setopt( $ch , CURLOPT_POST , true ); curl_setopt( $ch , CURLOPT_POSTFIELDS , $params ); curl_setopt( $ch , CURLOPT_URL , $url ); } else { if($params){ curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params ); }else{ curl_setopt( $ch , CURLOPT_URL , $url); } } $response = curl_exec( $ch ); if ($response === FALSE) { return false; } curl_close( $ch ); return $response; } }