/* aibang's api return josn data d_eng (sh109419@163.com) 2013-12-4 */ define("APP_KEY", "xx00ac396d6d75e8681fc8380060c5b2");include_once "ABClient.php";//header("Content-Type:text/html; charset=utf-8"); function bustransfer($city,$start,$end) { $client = new ABClient(APP_KEY); list($code, $arr) = $client->getBusTransfer($city, array("start_addr" =>$start, "end_addr" =>$end)); if ($code<>200){ return false; } $ret =""; $buses = $arr[buses][bus]; // show the top 3 records $ret = $start ."-->".$end."n"; $count = 1; foreach ($buses as $bus) { if ($count > 3) break; $segments =$bus[segments][segment]; $ret .= "<方案".$count++.">n"; // get line name and remove remark $linename = ""; foreach($segments as $segment) { if (!empty($linename)) $linename .= '--' ; $linename .= shortlinename($segment[line_name]); } $ret .= $linename . "n" ; $total = sprintf("%d分钟 %d米 步行%d米",$bus[time],$bus[dist],$bus[foot_dist]); $ret .= $total . "n" ; // detail $from = sprintf("从 %s ",$start); $ret .= $from; foreach($segments as $segment) { if ($segment[foot_dist] > 0) { $segfoot = sprintf("步行%d米 到达 %s",$segment[foot_dist],$segment[start_stat]); $ret .= $segfoot . "n" ; } $stats = substr_count($segment[stats],';'); $line = sprintf("乘坐 %s(%d站) 到达 %s",shortlinename($segment[line_name]),$stats,$segment[end_stat]); $ret .= $line . "n" ; } if ($bus[last_foot_dist] > 0) { $lastfoot = sprintf("步行%d米 到达 %s",$bus[last_foot_dist],$end); $ret .= $lastfoot; } } return $ret;}function shortlinename($linename){ return substr($linename,0,strpos($linename,'('));}$a=bustransfer("南昌","老福山","青山路口");var_dump($a);
3)效果展示
这样,公交换乘查找成功的机率就增加了。
以上就是微信公众平台开发--公交换乘的内容,更多相关内容请关注PHP中文网(www.php.cn)!