{ "data": { "destination": "116.434446,39.90816", "origin": "116.434307,39.90909", "paths": [ "0": { "distance": 217, "duration": 52, "steps": [ "0": { "action": "右转", "assistant_action": "", "distance": 54, "duration": 13, "instruction": "骑行54米右转", "orientation": "", "polyline": "116.434323,39.909049;116.434965,39.909049", "road": "" }, "1": { "action": "右转", "assistant_action": "", "distance": 115, "duration": 28, "instruction": "沿建国门北大街向南骑行115米右转", "orientation": "南", "polyline": "116.434965,39.909049;116.434931,39.908932;116.434887,39.908867;116.434887,39.908867;116.434818,39.908655;116.434826,39.908424;116.434883,39.908303;116.434883,39.908303;116.434974,39.908194;116.435009,39.908077", "road": "建国门北大街" }, "2": { "action": "", "assistant_action": "到达目的地", "distance": 48, "duration": 12, "instruction": "骑行48米到达目的地", "orientation": "", "polyline": "116.435009,39.908073;116.434449,39.908073", "road": "" } ] } ] }, "errcode": 0, "errdetail": null, "errmsg": "OK", "ext": null }
<?php /** * Created by PhpStorm. * User: FZS * Time: 2019/7/20 17:50 */ //---------------------------------- // 骑行路径规划 调用类 //---------------------------------- class freeApi{ private $apiUrl = 'https://restapi.amap.com/v4/direction/bicycling?origin=1,1&destination=1,1&key=key'; /** * 获取 骑行路径规划 结果 * @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; } }