1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | <?php include('common.inc.php'); if ($_REQUEST['time']) { $toPlace = geocode($_REQUEST['to'],false); $fromPlace = geocode($_REQUEST['from'],false); $url = "http://localhost:8080/opentripplanner-api-webapp/ws/plan?_dc=1290254798856&arriveBy=false&date=11%2F17%2F2010&time=1%3A06%20pm&mode=TRANSIT%2CWALK&optimize=QUICK&maxWalkDistance=840&wheelchair=false&toPlace=$toPlace&fromPlace=$fromPlace&intermediatePlaces="; $ch = curl_init($url); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json")); $page = curl_exec($ch); curl_close($ch); $tripplan = json_decode($page); echo "<h1> From: {$tripplan->plan->from->name} </h1>"; echo "<h1> To: {$tripplan->plan->to->name} </h1>"; echo "<h1> At: {$tripplan->plan->date} </h1>"; foreach ($tripplan->plan->itineraries->itinerary as $itineraryNumber => $itinerary ){ echo "<hr> <h2> Option #".($itineraryNumber+1)."<h2>"; echo "Duration: ".floor($itinerary->duration/60000)." minutes ({$itinerary->startTime} to {$itinerary->endTime})<br>\n"; echo "Walking time: ".floor($itinerary->walkTime/60000)." minutes ({$itinerary->walkDistance} meters)<br>\n"; echo "Transit time: ".floor($itinerary->transitTime/60000)." minutes<br>\n"; echo "Waiting time: ".floor($itinerary->waitingTime/60000)." minutes<br>\n"; $legMarkers = Array(); foreach ($itinerary->legs->leg as $legNumber => $leg ){ $legMarkers[] = Array($leg->from->lat,$leg->from->lon); } echo staticmap($legMarkers)."<br>\n"; foreach ($itinerary->legs->leg as $legNumber => $leg ){ echo "Leg #".($legNumber+1)." (from: {$leg->from->name} to {$leg->to->name}, ".floor($leg->duration/60000)." minutes) <br>\n"; $legArray = object2array($leg); if ($legArray["@mode"] === "BUS") { echo "Take bus {$legArray['@route']} ".str_replace("To","towards",$legArray['@headsign'])."<br>"; } else { foreach ($leg->steps->walkSteps as $stepNumber => $step ){ echo "Walking step $stepNumber $step->absoluteDirection / $step->relativeDirection on $step->streetName for $step->distance meters / ".floor($step->duration/60000)." minutes<br>\n"; } } } } } else { echo '<form> I would like to go from <input type="text" name="from" value="Brigalow"></input> to <input type="text" name="to" value="Barry"></input> on <input type="text" name="date" value="1:00pm"> at <input type="text" name="time" value="1:00pm"></input> <input type="submit"></form>'; } include_footer(); ?> |