{ "status": "1", "regeocode": { "addressComponent": { "city": [], "province": "北京市", "adcode": "110108", "district": "海淀区", "towncode": "110108015000", "streetNumber": { "number": "5号", "location": "116.310454,39.9927339", "direction": "东北", "distance": "94.5489", "street": "颐和园路" }, "country": "我们", "township": "燕园街道", "businessAreas": [{ "location": "116.303364,39.97641", "name": "万泉河", "id": "110108" }, { "location": "116.314222,39.98249", "name": "中关村", "id": "110108" }, { "location": "116.294214,39.99685", "name": "西苑", "id": "110108" } ], "building": { "name": "北京大学", "type": "科教文化服务;学校;高等院校" }, "neighborhood": { "name": "北京大学", "type": "科教文化服务;学校;高等院校" }, "citycode": "010" }, "formatted_address": "北京市海淀区燕园街道北京大学" }, "info": "OK", "infocode": "10000" }
<?php /** * Created by PhpStorm. * User: FZS * Time: 2019/7/20 17:50 */ //---------------------------------- // 逆地理编码 调用类 //---------------------------------- class freeApi{ private $apiUrl = 'https://restapi.amap.com/v3/geocode/regeo?key=youkey&location=116.310003,39.991957'; /** * 获取 逆地理编码 结果 * @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; } }