{ "status": 0, "type": 2, "result": { "origin": { "city_id": 131, "city_name": "北京市", "location": { "lng": 116.3081418168, "lat": 40.056871561538 } }, "destination": { "city_id": 289, "city_name": "上海市", "location": { "lng": 121.50581834502, "lat": 31.222960154925 } }, "total": 66, "routes": [{ "distance": 32975, "duration": 22657, "arrive_time": "2019-09-04 23:40:00", "price": 558, "price_detail": [], "steps": [ [{ "distance": 7, "duration": 5, "instructions": "站内换乘", "path": "121.5334322564,31.234840792595;121.53341429029,31.234840792595;121.53339632418,31.234802196475", "traffic_condition": [], "start_location": { "lng": 121.5334322564, "lat": 31.234848511818 }, "end_location": { "lng": 121.53340530724, "lat": 31.2348099157 }, "vehicle_info": { "type": 5, "detail": null } }, { "distance": 3478, "duration": 360, "instructions": "世纪大道站乘地铁9号线(松江南站方向)经过2站到小南门站(2口)", "path": "121.53340530724,31.2348099157;121.53340530724,31.2348099157;121.53284835782,31.235087807389;121.53232734062,31.235357979073;121.53161767927,31.235751656415;121.53133022151,31.235890600963;121.53127632318,31.235913758368;121.53106971291,31.235983230548;121.53020733962,31.236245680539;121.52819513528,31.236917240399;121.52751242309,31.237141092615;121.52712615172,31.237264597056;121.52696445673,31.237287754121;121.52657818536,31.237295473141;121.52288614971,31.236122174753;121.52288614971,31.236122174753;121.52203275948,31.235828847856;121.51876292742,31.234578338663;121.51384021323,31.231953758839;121.5056027517,31.226140824368;121.5052434295,31.225345667142;121.50500987007,31.223168600165;121.50489309035,31.22265134631", "traffic_condition": [], "start_location": { "lng": 121.53340530724, "lat": 31.2348099157 }, "end_location": { "lng": 121.50489309035, "lat": 31.22265134631 }, "vehicle_info": { "type": 3, "detail": { "name": "地铁9号线", "type": 1, "stop_num": 2, "on_station": "世纪大道站", "off_station": "小南门站", "first_time": "05:34", "last_time": "23:54" } } }, { "distance": 212, "duration": 178, "instructions": "步行212米", "path": "121.50488410729,31.222643626081;121.50488410729,31.222643626081;121.5048032598,31.222265334108;121.5048032598,31.222265334108;121.50521648033,31.222195851742;121.5052434295,31.222195851742;121.5052434295,31.222195851742;121.5052434295,31.222319375912;121.5052434295,31.222319375912;121.50502783618,31.222327096167;121.50509071756,31.22255098329;121.50509970062,31.22260502493;121.50512664978,31.222890673076;121.50514461589,31.22300647613", "traffic_condition": [], "start_location": { "lng": 121.50489309035, "lat": 31.22265134631 }, "end_location": { "lng": 121.50581834502, "lat": 31.222960154925 }, "vehicle_info": { "type": 5, "detail": null } }] ] }, { "distance": 52087, "duration": 23851, "arrive_time": "2019-09-04 21:36:00", "price": 553, "price_detail": [], "steps": [ [{ "distance": 792, "duration": 675, "instructions": "步行792米", "path": "116.30825859651,40.056899174073;116.30812385069,40.057182201905;116.30803402013,40.057410003934;116.30786334209,40.057768963149;116.30771961321,40.058045084326;116.30771063015,40.058072696381;116.30767469793,40.058176241489;116.30772859626,40.058196950492;116.30774656237,40.05821075649;116.30774656237,40.058238368478;116.30771961321,40.058307398398;116.30771063015,40.058348816317;116.30768368099,40.058362622284;116.30765673182,40.058376428248;116.30762978266,40.058376428248;116.30727046045,40.05830049541;116.30728842656,40.05839713719;116.30733334184,40.058486875862;116.30734232489,40.058555905529;116.30799808791,40.058693964651;116.30875266454,40.058859635225;116.30953419034,40.059052917048;116.31086368249,40.059356644512;116.31104334359,40.059398061787;116.31136673358,40.059467090524;116.3114026658,40.059473993393;116.31142961496,40.059480896262;116.31151046246,40.059494701998;116.31156436079,40.059501604865;116.31160029301,40.059501604865;116.31163622523,40.059487799131;116.31168114051,40.059508507732;116.31174402189,40.059536119189;116.31182486939,40.05939115891;116.31189673383,40.059260004103;116.31188775077,40.059260004103;116.31214825937,40.05939115891;116.31214825937,40.05939115891;116.31226503909,40.05942567329;116.31226503909,40.05942567329;116.31261537824,40.058907955733;116.31265131046,40.058921761586", "traffic_condition": [], "start_location": { "lng": 116.3081418168, "lat": 40.056871561538 }, "end_location": { "lng": 116.31266029351, "lat": 40.058921761586 }, "vehicle_info": { "type": 5, "detail": null } }, { "distance": 13345, "duration": 1140, "instructions": "西二旗站(A1口)乘地铁13号线(西直门方向)经过5站到西直门站", "path": "116.31266029351,40.058921761586;116.31266029351,40.058921761586;116.31298368349,40.05828668943;116.31505876922,40.055028399332;116.31619961722,40.053495844184;116.31922690679,40.049595265593;116.32103250086,40.04730313924;116.32308962048,40.044693334536;116.32457182457,40.043008645212;116.3254072487,40.041765814717;116.32656606281,40.039328419721;116.32683555446,40.038693163539;116.32683555446,40.038693163539;116.32706911389,40.038120046865;116.33010538652,40.030372137803;116.33232420112,40.024943929738;116.33297098109,40.024059905521;116.34142403594,40.01652451175;116.34252895172,40.015446971686;116.34322064696,40.014466119026;116.34365183361,40.013423084059;116.34383149471,40.012518186403;116.34389437609,40.010950129007;116.34385844387,40.010197172243;116.34410098636,40.007371782767;116.3444333594,39.998563271813;116.3444333594,39.998563271813;116.3446130205,39.994016941184;116.34471183411,39.992545191289;116.34525081741,39.989663785561;116.3458526821,39.986063583697;116.34640963152,39.983112795804;116.3466342079,39.982062367237;116.3466342079,39.982062367237;116.34687675039,39.981115585435;116.34714624204,39.980369207979;116.34898776833,39.977984891604;116.35096404046,39.975289476463;116.35135031183,39.974473919484;116.35161082042,39.973471738576;116.35181743069,39.972027189687;116.35181743069,39.972027189687;116.35196115957,39.970983501246;116.35224861734,39.969193296248;116.35232946483,39.968695624688;116.3527965837,39.967043605409;116.35352421116,39.965557444897;116.3549974322,39.962695630139;116.35694675515,39.959100909125;116.3582582812,39.956453137021;116.35830319647,39.955706488089;116.35793489121,39.953590938161;116.35788997594,39.952519310905;116.3597584514,39.94745823608", "traffic_condition": [], "start_location": { "lng": 116.31266029351, "lat": 40.058921761586 }, "end_location": { "lng": 116.3597584514, "lat": 39.94745823608 }, "vehicle_info": { "type": 3, "detail": { "name": "地铁13号线", "type": 1, "stop_num": 5, "on_station": "西二旗站(A1口)", "off_station": "西直门站", "first_time": "05:11", "last_time": "23:19" } } }, { "distance": 402, "duration": 334, "instructions": "站内换乘 步行402米", "path": "116.35974946834,39.947451321785;116.35977641751,39.947451321785;116.35973150223,39.947561950418;116.35973150223,39.947589607548;116.3601177736,39.947575778984;116.3601177736,39.947575778984;116.36113285883,39.946925833318;116.36151014714,39.946656173183;116.36223777461,39.946123764129;116.36210302878,39.946020047593", "traffic_condition": [], "start_location": { "lng": 116.3597584514, "lat": 39.94745823608 }, "end_location": { "lng": 116.36211201184, "lat": 39.946020047593 }, "vehicle_info": { "type": 5, "detail": null } }, { "distance": 9896, "duration": 1080, "instructions": "西直门站乘地铁4号线大兴线(天宫院方向)经过9站到北京南站(C口)", "path": "116.36211201184,39.946020047593;116.36211201184,39.946020047593;116.36481591142,39.946213651665;116.36942421869,39.946386511976;116.37413133956,39.946580115002;116.37413133956,39.946580115002;116.37789523965,39.946676916308;116.37835337546,39.946593943769;116.37890134182,39.946317367905;116.37915286736,39.945923245351;116.37931456235,39.939748359884;116.37931456235,39.939748359884;116.37972778289,39.931027884146;116.37976371511,39.930246375256;116.37976371511,39.930246375256;116.37979066427,39.929478689626;116.38021286786,39.922963386572;116.38022185092,39.922133366781;116.38022185092,39.922133366781;116.38024880008,39.921123495693;116.38032964758,39.9205908864;116.38051829174,39.914607391176;116.38057219007,39.913306862386;116.38057219007,39.913306862386;116.38059913923,39.911985554986;116.38079676644,39.906921458347;116.38084168172,39.905876768511;116.38084168172,39.905876768511;116.38096744449,39.895380549836;116.38096744449,39.895380549836;116.38089558005,39.884619724788;116.38089558005,39.884619724788;116.38089558005,39.880155731832;116.38117405476,39.879020654354;116.3817849025,39.878217783239;116.38269219107,39.877318002626;116.38325812354,39.876715835108;116.38402168322,39.875608386679;116.38460558181,39.874493998502;116.38497388706,39.873400357578;116.38509066678,39.872521279029;116.38509066678,39.871697565201;116.38515354817,39.871178412708", "traffic_condition": [], "start_location": { "lng": 116.36211201184, "lat": 39.946020047593 }, "end_location": { "lng": 116.38515354817, "lat": 39.871178412708 }, "vehicle_info": { "type": 3, "detail": { "name": "地铁4号线大兴线", "type": 1, "stop_num": 9, "on_station": "西直门站", "off_station": "北京南站", "first_time": "05:25", "last_time": "23:10" } } }, { "distance": 408, "duration": 342, "instructions": "步行408米", "path": "116.38514456511,39.871178412708;116.38513558206,39.871164568587;116.38518948039,39.870707711024;116.38518948039,39.870707711024;116.38580931119,39.870728477343;116.38580931119,39.870728477343;116.3858272773,39.870555424488;116.3858272773,39.870534658116;116.3858272773,39.870534658116;116.38678846419,39.869911664003;116.38678846419,39.869904741814;116.3865279556,39.869766297889;116.38553981954,39.869316353188", "traffic_condition": [], "start_location": { "lng": 116.38515354817, "lat": 39.871178412708 }, "end_location": { "lng": 116.3850277854, "lat": 39.870437748295 }, "vehicle_info": { "type": 5, "detail": null } }], [{ "distance": 0, "duration": 16560, "instructions": "北京南站乘坐G13到达上海虹桥站 ", "path": "116.38548592121,39.871275321474;116.89802311298,36.67526195637;118.80433520181,31.975021252677;120.64981404151,31.427321653326;121.32699266715,31.200545723645", "traffic_condition": [], "start_location": { "lng": 116.38548592121, "lat": 39.871275321474 }, "end_location": { "lng": 121.32699266715, "lat": 31.200545723645 }, "vehicle_info": { "type": 1, "detail": { "name": "G13", "price": 553, "departure_station": "北京南站", "arrive_station": "上海虹桥站", "departure_time": "017:00", "arrive_time": "021:36", "start_info": { "start_name": "北京南站", "start_city": "北京", "start_time": "2019-09-04 17:00:00" }, "end_info": { "end_name": "上海虹桥站", "end_city": "上海", "end_time": "2019-09-04 21:36:00" }, "booking": "12306" } } }], [{ "distance": 214, "duration": 177, "instructions": "步行214米", "path": "121.32722622659,31.201835297277;121.32712741298,31.201835297277;121.32712741298,31.201356535485;121.32728012492,31.200630666166;121.32728012492,31.200630666166;121.32728012492,31.200584333891;121.32728012492,31.200298617688;121.32728910797,31.200298617688;121.32788198961,31.200329505968;121.32789995572,31.20031406183", "traffic_condition": [], "start_location": { "lng": 121.32720826048, "lat": 31.199935679633 }, "end_location": { "lng": 121.32789995572, "lat": 31.200321783899 }, "vehicle_info": { "type": 5, "detail": null } }, { "distance": 23333, "duration": 2400, "instructions": "虹桥火车站(出口)乘地铁2号线(浦东国际机场方向)经过14站到世纪大道站", "path": "121.32789995572,31.200321783899;121.32789995572,31.200321783899;121.32938215981,31.200383560434;121.3298043634,31.200437614869;121.33178961858,31.200931825396;121.33205012717,31.200962713468;121.33266097492,31.200985879515;121.33266097492,31.200985879515;121.33341555155,31.200985879515;121.33788012993,31.200815995038;121.33869758795,31.200870049223;121.33957792735,31.201186651681;121.33997318177,31.201565028824;121.34076369062,31.203001303661;121.34112301283,31.203912477355;121.34099725005,31.20470009493;121.33891318127,31.209147693401;121.33787114688,31.211633932444;121.3373860619,31.214259082142;121.33776335022,31.218629021032;121.33823046908,31.220914278863;121.33887724905,31.222504661861;121.33936233403,31.222967875128;121.33977555456,31.223230361628;121.34061996174,31.22366269073;121.342129115,31.224025536827;121.34321606466,31.224195379198;121.34437487877,31.224457862256;121.34553369288,31.224619983776;121.34665657477,31.22476666491;121.34801301609,31.224874745599;121.34989945766,31.224928785896;121.3508516615,31.224836145367;121.35380708663,31.224720344577;121.35822674974,31.224519622868;121.35990658104,31.224419261852;121.36220624314,31.224342060997;121.36471251552,31.224056417281;121.36600607545,31.223948335648;121.36600607545,31.223948335648;121.36734455066,31.223840253889;121.37420760476,31.223353884432;121.37472862195,31.223299843225;121.37690252129,31.222906113491;121.37922913256,31.222458340408;121.38063947221,31.222103208508;121.38063947221,31.222103208508;121.38187015076,31.221802117364;121.38214862547,31.221763515865;121.38257082906,31.221701753434;121.38329845652,31.221647711273;121.38519388114,31.221578228449;121.38635269525,31.221493304928;121.38930812038,31.221253974589;121.39041303616,31.221138169366;121.39197608774,31.220844795495;121.3927845627,31.220667226652;121.3936649021,31.220481937066;121.3936649021,31.220481937066;121.39582083533,31.220034152386;121.39948592181,31.219292986828;121.40248626221,31.218698506045;121.40448050044,31.218320198127;121.40680711171,31.217633063508;121.40939423158,31.2171852652;121.41081355429,31.216953644544;121.41081355429,31.216953644544;121.41166694452,31.216845554709;121.41194541923,31.216837834002;121.41271796197,31.216899599642;121.41535898017,31.218289315781;121.41700287925,31.219941507012;121.4179730492,31.220775312075;121.42122491515,31.223685851161;121.42215915288,31.224110458051;121.42485406941,31.224720344577;121.42485406941,31.224720344577;121.42654288377,31.225098626628;121.43054932634,31.225222146966;121.43452881975,31.225098626628;121.43574153219,31.225276187063;121.43694526157,31.225615866957;121.4380411943,31.225947825662;121.43893949981,31.22620258387;121.43893949981,31.22620258387;121.44001746642,31.226503660858;121.44097865331,31.226596299736;121.44147272134,31.226534540494;121.44196678938,31.226411021888;121.44292797627,31.225847466178;121.44339509514,31.225808866348;121.44391611233,31.225901505914;121.44627865582,31.226920535088;121.44685357135,31.227167570792;121.44732967327,31.227306528089;121.44881187736,31.227584442064;121.44982696259,31.228047630189;121.45241408246,31.229421741468;121.45270154022,31.2295452561;121.45270154022,31.2295452561;121.45519882954,31.230649160885;121.45597137228,31.231042858042;121.4598879843,31.233103951413;121.46544849541,31.23571306067;121.46654442813,31.236044983553;121.46654442813,31.236044983553;121.46893392078,31.236762859249;121.47014663322,31.236971273742;121.47452138106,31.237341787249;121.47640782263,31.237542481453;121.47726121286,31.237835802976;121.47926443415,31.238785232125;121.47926443415,31.238785232125;121.48098918073,31.239657463418;121.48128562155,31.239819558603;121.48223782539,31.240359873857;121.48335172422,31.240799842544;121.48804986204,31.242065705819;121.49031359192,31.242907032297;121.49031359192,31.242907032297;121.49484105169,31.244404420334;121.49663766271,31.244643691459;121.50280902157,31.244720875562;121.50491105646,31.244612817799;121.50827970212,31.244026216341;121.50898038042,31.243810099086;121.50898038042,31.243810099086;121.50966309261,31.24357854433;121.51843055438,31.240228654725;121.51970614821,31.239796402166;121.52199682726,31.239078549751;121.52199682726,31.239078549751;121.52713513478,31.237449853412;121.52781784696,31.237202844856;121.53134818762,31.235936915767;121.53170750982,31.235751656415;121.53236327284,31.235388855787;121.5334322564,31.234848511818", "traffic_condition": [], "start_location": { "lng": 121.32789995572, "lat": 31.200321783899 }, "end_location": { "lng": 121.5334322564, "lat": 31.234848511818 }, "vehicle_info": { "type": 3, "detail": { "name": "地铁2号线", "type": 1, "stop_num": 14, "on_station": "虹桥火车站(出口)", "off_station": "世纪大道站", "first_time": "05:31", "last_time": "22:48" } } }, { "distance": 7, "duration": 5, "instructions": "站内换乘", "path": "121.5334322564,31.234840792595;121.53341429029,31.234840792595;121.53339632418,31.234802196475", "traffic_condition": [], "start_location": { "lng": 121.5334322564, "lat": 31.234848511818 }, "end_location": { "lng": 121.53340530724, "lat": 31.2348099157 }, "vehicle_info": { "type": 5, "detail": null } }, { "distance": 3478, "duration": 360, "instructions": "世纪大道站乘地铁9号线(松江南站方向)经过2站到小南门站(2口)", "path": "121.53340530724,31.2348099157;121.53340530724,31.2348099157;121.53284835782,31.235087807389;121.53232734062,31.235357979073;121.53161767927,31.235751656415;121.53133022151,31.235890600963;121.53127632318,31.235913758368;121.53106971291,31.235983230548;121.53020733962,31.236245680539;121.52819513528,31.236917240399;121.52751242309,31.237141092615;121.52712615172,31.237264597056;121.52696445673,31.237287754121;121.52657818536,31.237295473141;121.52288614971,31.236122174753;121.52288614971,31.236122174753;121.52203275948,31.235828847856;121.51876292742,31.234578338663;121.51384021323,31.231953758839;121.5056027517,31.226140824368;121.5052434295,31.225345667142;121.50500987007,31.223168600165;121.50489309035,31.22265134631", "traffic_condition": [], "start_location": { "lng": 121.53340530724, "lat": 31.2348099157 }, "end_location": { "lng": 121.50489309035, "lat": 31.22265134631 }, "vehicle_info": { "type": 3, "detail": { "name": "地铁9号线", "type": 1, "stop_num": 2, "on_station": "世纪大道站", "off_station": "小南门站", "first_time": "05:34", "last_time": "23:54" } } }] } ]] }]] }], "taxi": null }, "message": "成功" }
<?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/direction/v2/transit?origin=40.056878,116.30815&destination=31.222965,121.505821&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 , 'free-api' ); 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; } }