/**
The xml should be
<Address>
<Value></Value>
<Info></Info>
<Stops>
<Stop>
<Name></Name>
<Latitude></Latitude>
<Longitude></Longitude>
<Distance></Distance>
<Buses></Buses>
</Stop>
.
.
</Stops>
<Result>
<BusStop></BusStop>
<BusStopLatitude></BusStopLatitude>
<BusStopLongitude></BusStopLongitude>
<Offset></Offset>
</Result>
</Address>
 **/
function getStopForAddress($addr, $log, $mediaType)
{
    //echo $addr;
    $stopDataString = '';
    $originalRequestedLatitude = 0;
    $originalRequestedLongitude = 0;
    // create a xml string
    $stopXMLString = '<Address>';
    $query = "Select StopName, Latitude, Longitude from Stops Where StopName = '" . $addr . "'";
    $result = mysql_query($query);
    $rowsnum = mysql_num_rows($result);
    //find from the stop table..more than one stop found
    //	if($rowsnum>1)
    //	{
    //		if($DEBUG)
    //			echo "more than one stops are found with your search criteria <br/>";
    //		$log->LogDebug("[".$mediaType."] The address ".$addr." matches more than one in stops table. taking the first one ");
    //		$stopXMLString=$stopXMLString."<Info>More than one stops are found with your search criteria</Info>";
    //		$stopXMLString=$stopXMLString."<ErrorCode>MS</ErrorCode>";
    //		$stopXMLString=$stopXMLString."<Stops>";
    //		// this is the case wehre we can check which is the best choice in terms of buses coming thourgh..E.g. Marathahalli
    //		$maxBus=0;
    //		for($i=0;$i<$rowsnum;$i++)
    //		{
    //			$row=mysql_fetch_row($result);
    //			$stopXMLString=$stopXMLString."<Stop>";
    //		   if($DEBUG)
    //			 echo $row[0]."<br/>";
    //
    //			$stopXMLString=$stopXMLString."<Name>".htmlentities($row[0])."</Name>";
    //			$stopXMLString=$stopXMLString."<Latitude>".$row[1]."</Latitude>";
    //			$stopXMLString=$stopXMLString."<Longitude>".$row[2]."</Longitude>";
    //			$stopXMLString=$stopXMLString."<Distance>-1</Distance>";
    //			$stopXMLString=$stopXMLString."<Buses>".getBusesForStop($row[0])."</Buses>";
    //
    //			// $stopDetails=$row[0];
    //			//$map->addMarkerByCoords($row[2],$row[1],$row[0],getBusesForStop($row[0]),'');
    //			$NumberOfBus=getNumberOfBusesForStop($row[0]);
    //			if($NumberOfBus>$maxBus)
    //			{
    //				$maxBus=$NumberOfBus;
    //				$stopDataString=$row[0].":".$row[1].":".$row[2].":0";
    //			}
    //			$stopXMLString=$stopXMLString."</Stop>";
    //		}
    //		$stopXMLString=$stopXMLString."</Stops>";
    //	}
    //	else //only one stop is found
    // if the stop is found
    if ($rowsnum == 1) {
        $stopXMLString = $stopXMLString . "<Info>Your address matches the correct stop name</Info>";
        $stopXMLString = $stopXMLString . "<ErrorCode>OS</ErrorCode>";
        $stopXMLString = $stopXMLString . "<Stops>";
        $stopXMLString = $stopXMLString . "<Stop>";
        $row = mysql_fetch_row($result);
        //        if($DEBUG)
        //            echo " Your stop is ".$row[0]."<br/>";
        $log->LogDebug("[" . $mediaType . "] The address " . $addr . " is a valid stopname ");
        $stopXMLString = $stopXMLString . "<Name>" . htmlentities($row[0]) . "</Name>";
        $stopXMLString = $stopXMLString . "<Latitude>" . $row[1] . "</Latitude>";
        $stopXMLString = $stopXMLString . "<Longitude>" . $row[2] . "</Longitude>";
        $stopXMLString = $stopXMLString . "<Distance>-1</Distance>";
        $stopXMLString = $stopXMLString . "<Buses>" . getBusesForStop($row[0]) . "</Buses>";
        $stopXMLString = $stopXMLString . "</Stop>";
        // $map->addMarkerByCoords($row[2],$row[1],$row[0],getBusesForStop($row[0]),'');
        $stopDataString = $row[0] . ":" . $row[1] . ":" . $row[2] . ":0";
        $stopXMLString = $stopXMLString . "</Stops>";
    } else {
        //no stop found..user must have entered some free string
        if ($rowsnum == 0) {
            //First check in the road database if the address meets
            //echo "going to the roads database"."<br/>";
            // Checking in the road database
            $query = "Select * from newRoadAddresses Where Address ='" . $addr . "'";
            $result = mysql_query($query);
            $rowsnum = mysql_num_rows($result);
            //the address was not found in the road database so get it from internet
            if ($rowsnum == 0) {
                //                if($DEBUG)
                //                    echo "The address not found in the database so fetching from internet <br/>";
                //$stopXMLString=$stopXMLString."<Info>The address ".$addr." not found in the database so fetching from internet</Info>";
                $logString = "[" . $mediaType . "] The address " . $addr . " not found in the database so fetching from internet ";
                //$log->LogDebug("[".$mediaType."] The address ".$addr." not found in the database so fetching from internet ");
                // fimd from the net
                $addressString = "http://maps.google.com/maps/api/geocode/json?address=" . urlencode($addr) . ",+Bangalore,+Karnataka,+India&sensor=false";
                $geocode = file_get_contents($addressString);
                $formattedAddress = return_between($geocode, "formatted_address", "\",", EXCL);
                $formattedAddressNoiseRemoved = return_between($formattedAddress, ":", "India", INCL);
                $place = substr($formattedAddressNoiseRemoved, 3);
                //echo $place."<br/>";
                //exit(0);
                ///echo $place."<br/>";
                //$arr=array();
                $arr = explode(",", $place);
                //the address was not at all valid
                if (strcmp(trim($arr[0]), "Bangalore") == 0 && strcmp(trim($arr[1]), "Karnataka") == 0 && strcmp(trim($arr[2]), "India") == 0) {
                    $log->LogDebug($logString . ". Invalid Address provided ");
                    $stopXMLString = $stopXMLString . "<Info>Address is not valid. Try giving some locality name</Info>";
                    $stopXMLString = $stopXMLString . "<ErrorCode>AM</ErrorCode>";
                    $stopXMLString = $stopXMLString . "<Stops>";
                    $stopXMLString = $stopXMLString . "<Stop>";
                    $stopXMLString = $stopXMLString . "</Stop>";
                    $stopXMLString = $stopXMLString . "</Stops>";
                    //                    if($DEBUG)
                    //                        echo "<h3>".trim($addr)."  Address is not valid"."</h3><br/>";
                    $stopDataString = "0:0:0:0";
                } else {
                    $locations = return_between($geocode, "location", "}", EXCL);
                    //echo $locations;
                    $latitude = return_between($locations, "lat\"", ",", EXCL);
                    $latitude = substr($latitude, 3);
                    //echo $latitude;
                    list($lat, $long) = explode(",", $locations);
                    list($cap, $val) = explode(":", $long);
                    //echo trim($val);
                    $addrLat = trim($latitude);
                    $addrLong = trim($val);
                    $originalRequestedLatitude = $addrLat;
                    $originalRequestedLongitude = $addrLong;
                    // add the marker for the searched address
                    //$map->addMarkerIcon("marker_star.png","marker_shadow.png",15,29,15,3);
                    //$map->addMarkerByCoords($addrLong,$addrLat,$addr,'','');
                    //Now check that we have any stop that is within 1 km of the stop.
                    //we need to use the direct method to calculate the distance
                    // we could have used the heversine formaula also but this is OK
                    $query = "SELECT  StopName, Latitude, Longitude FROM Stops WHERE (Latitude - " . $addrLat . " < .009) AND (Latitude - " . $addrLat . " > - .009) AND (Longitude - " . $addrLong . " > - .009) AND (Longitude - " . $addrLong . " < 0.009)";
                    //echo $query."<br/>";
                    $result = mysql_query($query);
                    $rowsnum = mysql_num_rows($result);
                    //we could not find any stops near to this address.
                    if ($rowsnum == 0) {
                        // this is the case when you gave an address that even could not be found usign the internet search
                        $log->LogDebug($logString . ". No Stops nearby");
                        $stopXMLString = $stopXMLString . "<Info>Sorry we could not find any stops nearby</Info>";
                        $stopXMLString = $stopXMLString . "<ErrorCode>AM</ErrorCode>";
                        $stopXMLString = $stopXMLString . "<Stops>";
                        $stopXMLString = $stopXMLString . "<Stop>";
                        $stopXMLString = $stopXMLString . "</Stop>";
                        $stopXMLString = $stopXMLString . "</Stops>";
                        //                        if($DEBUG)
                        //                            echo "<h3>".trim($addr)."  Address is not valid"."</h3><br/>";
                        $stopDataString = "0:0:0:0";
                    } else {
                        $arrBusStops = array();
                        for ($i = 0; $i < $rowsnum; $i++) {
                            $row = mysql_fetch_row($result);
                            //echo $row[0];
                            $dist = distance($addrLat, $addrLong, $row[1], $row[2], "K");
                            $BDS = new BusDataStructure($row[0], $row[1], $row[2], $dist);
                            array_push($arrBusStops, $BDS);
                            //echo distance($addrLat, $addrLong, $row[1],$row[2], "K") . " kilometers<br>";
                            //$map->addMarkerByCoords($row[2],$row[1],$row[0].distance($addrLat, $addrLong, $row[1],$row[2], "K"),'','');
                        }
                        // now do the comparison of the data
                        //sort the stops in the order of some preference
                        $tempSortedArray = BubbleSort($arrBusStops, $rowsnum);
                        // this is the place to do One more level of filtering based on the number of buses
                        $sortedArray = applyFilterForAddress($tempSortedArray);
                        //print_r($sortedArray);
                        $log->LogDebug($logString . ". Valid Address found via internet");
                        $stopXMLString = $stopXMLString . "<Info>Address Found via Internet</Info>";
                        $formattedPlace = preg_replace('/Bangalore, Karnataka, India$/', '', $place);
                        $formattedPlaceRemovingTrailingComma = rtrim(trim($formattedPlace), ",");
                        $stopXMLString = $stopXMLString . "<InternetAddress>" . $formattedPlaceRemovingTrailingComma . "</InternetAddress>";
                        $stopXMLString = $stopXMLString . "<ErrorCode>IA</ErrorCode>";
                        $stopXMLString = $stopXMLString . "<Stops>";
                        for ($i = 0; $i < sizeof($sortedArray); $i++) {
                            //echo $sortedArray[$i]->getStopName().$sortedArray[$i]->getDistance()."<br/>";
                            $stopXMLString = $stopXMLString . "<Stop>";
                            //$map->addMarkerByCoords($sortedArray[$i]->getLongitude(),$sortedArray[$i]->getLatitude(),$sortedArray[$i]->getStopName().$sortedArray[$i]->getDistance(),getBusesForStop($sortedArray[$i]->getStopName()),'');
                            $stopXMLString = $stopXMLString . "<Name>" . htmlentities($sortedArray[$i]->getStopName()) . "</Name>";
                            $stopXMLString = $stopXMLString . "<Latitude>" . $sortedArray[$i]->getLatitude() . "</Latitude>";
                            $stopXMLString = $stopXMLString . "<Longitude>" . $sortedArray[$i]->getLongitude() . "</Longitude>";
                            $stopXMLString = $stopXMLString . "<Distance>" . $sortedArray[$i]->getDistance() . "</Distance>";
                            $stopXMLString = $stopXMLString . "<Buses>" . getBusesForStop($sortedArray[$i]->getStopName()) . "</Buses>";
                            $stopXMLString = $stopXMLString . "</Stop>";
                        }
                        $stopXMLString = $stopXMLString . "</Stops>";
                        $stopDataString = $sortedArray[0]->getStopName() . ":" . $sortedArray[0]->getLatitude() . ":" . $sortedArray[0]->getLongitude() . ":" . $sortedArray[0]->getDistance();
                    }
                }
            } else {
                if ($rowsnum > 1) {
                    $stopXMLString = $stopXMLString . "<Info>More than one matching address found in road database. Kindly add some more specifics</Info>";
                    $stopXMLString = $stopXMLString . "<ErrorCode>MA</ErrorCode>";
                    $stopXMLString = $stopXMLString . "<Stops>";
                    $stopXMLString = $stopXMLString . "<Stop>";
                    $stopXMLString = $stopXMLString . "</Stop>";
                    $stopXMLString = $stopXMLString . "</Stops>";
                    //                if($DEBUG)
                    //                    echo "More than one matching address found in road database. Kindly add some more specifics";
                    $stopDataString = "m:m:m:m";
                } else {
                    //                if($DEBUG)
                    //                    echo "Found in the road database"."<br/>";
                    // we found the address in th road data base but unfortunately all the stops are more than KM .
                    // this issue will not be there after we have the pegging of the stops.
                    // in the first sql itself we will know the stop that is meant for this road address
                    $log->LogDebug("[" . $mediaType . "] The address " . $addr . " found in the road database ");
                    $row = mysql_fetch_row($result);
                    $addrLat = $row[3];
                    $addrLong = $row[4];
                    $stopNumber = $row[5];
                    $stopName = $row[6];
                    $vicinityDistance = $row[7];
                    $originalRequestedLatitude = $addrLat;
                    $originalRequestedLongitude = $addrLong;
                    //get the latutude/logitude of the stop
                    $sqlStop = "Select * from Stops where SNo='" . $stopNumber . "'";
                    $resultStop = mysql_query($sqlStop);
                    $rowStop = mysql_fetch_row($resultStop);
                    $stopLat = $rowStop[2];
                    $stopLon = $rowStop[3];
                    $stopXMLString = $stopXMLString . "<Info>Address Found in the Road Database</Info>";
                    $stopXMLString = $stopXMLString . "<ErrorCode>RA</ErrorCode>";
                    $stopXMLString = $stopXMLString . "<Stops>";
                    $stopXMLString = $stopXMLString . "<Stop>";
                    //$map->addMarkerByCoords($sortedArray[$i]->getLongitude(),$sortedArray[$i]->getLatitude(),$sortedArray[$i]->getStopName().$sortedArray[$i]->getDistance(),getBusesForStop($sortedArray[$i]->getStopName()),'');
                    $stopXMLString = $stopXMLString . "<Name>" . htmlentities($stopName) . "</Name>";
                    $stopXMLString = $stopXMLString . "<Latitude>" . $stopLat . "</Latitude>";
                    $stopXMLString = $stopXMLString . "<Longitude>" . $stopLon . "</Longitude>";
                    $stopXMLString = $stopXMLString . "<Distance>" . $vicinityDistance . "</Distance>";
                    $stopXMLString = $stopXMLString . "<Buses>" . getBusesForStop($stopName) . "</Buses>";
                    $stopXMLString = $stopXMLString . "</Stop>";
                    $stopXMLString = $stopXMLString . "</Stops>";
                    $stopDataString = $stopName . ":" . $stopLat . ":" . $stopLon . ":" . $vicinityDistance;
                    //echo $addrLat;
                    //$map->addMarkerByCoords($addrLong,$addrLat,$addr,'','');
                    /*$query="SELECT  StopName, Latitude, Longitude FROM Stops WHERE (Latitude - ".$addrLat." < .009) AND (Latitude - ".$addrLat." > - .009) AND (Longitude - ".$addrLong." > - .009) AND (Longitude - ".$addrLong." < 0.009)";
                                    //echo $query."<br/>";
                                    $result= mysql_query($query);
                                    $rowsnum = mysql_num_rows($result);
                                    if($rowsnum==0)
                                    {
                                        $stopXMLString=$stopXMLString."<Info>All stops are more then 1 km far</Info>";
                                        $stopXMLString=$stopXMLString."<ErrorCode>KM</ErrorCode>";
                                        $stopXMLString=$stopXMLString."<Stops>";
                                        $stopXMLString=$stopXMLString."<Stop>";
                                        $stopXMLString=$stopXMLString."</Stop>";
                                        $stopXMLString=$stopXMLString."</Stops>";
                                        //echo "All stops are more then 1 km far";
                                    }
                                    else
                                    {
                                        // we should try to show nearest 5 at the max
                                        // one way is to create a array of datastructure and then sort them on the basis of distance.
                                        // also find the buses for the finalised stops
                                        $arrBusStops= array();
                                        $stopXMLString=$stopXMLString."<Info>Address Found in the Road Database</Info>";
                                        $stopXMLString=$stopXMLString."<ErrorCode>RA</ErrorCode>";
                                        for($i=0;$i<$rowsnum;$i++)
                                        {
                                            $row=mysql_fetch_row($result);
                                            $dist=distance($addrLat, $addrLong, $row[1],$row[2], "K");
                                            $BDS= new BusDataStructure($row[0],$row[1],$row[2],$dist);
                                            array_push($arrBusStops,$BDS);
                    
                                        }
                                        // now do the comparison of the data
                                        $tempSortedArray=BubbleSort($arrBusStops,$rowsnum);
                                        // this is the place to do One more level of filtering based on the number of buses
                                        $sortedArray=applyFilterForAddress($tempSortedArray);
                                        //print_r($sortedArray);
                                        $stopXMLString=$stopXMLString."<Stops>";
                                        for($i=0;$i<sizeof($sortedArray);$i++)
                                        {
                                            //echo $sortedArray[$i]->getStopName().$sortedArray[$i]->getDistance()."<br/>";
                                        $stopXMLString=$stopXMLString."<Stop>";	//$map->addMarkerByCoords($sortedArray[$i]->getLongitude(),$sortedArray[$i]->getLatitude(),$sortedArray[$i]->getStopName().$sortedArray[$i]->getDistance(),getBusesForStop($sortedArray[$i]->getStopName()),'');
                                        $stopXMLString=$stopXMLString."<Name>".htmlentities($sortedArray[$i]->getStopName())."</Name>";
                                        $stopXMLString=$stopXMLString."<Latitude>".$sortedArray[$i]->getLatitude()."</Latitude>";
                                        $stopXMLString=$stopXMLString."<Longitude>".$sortedArray[$i]->getLongitude()."</Longitude>";
                                        $stopXMLString=$stopXMLString."<Distance>".$sortedArray[$i]->getDistance()."</Distance>";
                                        $stopXMLString=$stopXMLString."<Buses>".getBusesForStop($sortedArray[$i]->getStopName())."</Buses>";
                                        $stopXMLString=$stopXMLString."</Stop>";
                    
                                        }
                                        $stopXMLString=$stopXMLString."</Stops>";
                                        $stopDataString=$sortedArray[0]->getStopName().":".$sortedArray[0]->getLatitude().":".$sortedArray[0]->getLongitude().":".$sortedArray[0]->getDistance();
                    
                                    }*/
                }
            }
        }
    }
    $stopXMLString = $stopXMLString . "<Result>";
    list($BusStop, $BusLatitude, $BusLongitude, $BusOffset) = explode(":", $stopDataString);
    $stopXMLString = $stopXMLString . "<BusStop>" . htmlentities($BusStop) . "</BusStop>";
    $stopXMLString = $stopXMLString . "<BusStopLatitude>" . $BusLatitude . "</BusStopLatitude>";
    $stopXMLString = $stopXMLString . "<BusStopLongitude>" . $BusLongitude . "</BusStopLongitude>";
    $stopXMLString = $stopXMLString . "<Offset>" . $BusOffset . "</Offset>";
    $stopXMLString = $stopXMLString . "<Buses>" . getBusesForStopWithFrequency($BusStop) . "</Buses>";
    $stopXMLString = $stopXMLString . "<OriginalStopLatitude>" . $originalRequestedLatitude . "</OriginalStopLatitude>";
    $stopXMLString = $stopXMLString . "<OriginalStopLongitude>" . $originalRequestedLongitude . "</OriginalStopLongitude>";
    $stopXMLString = $stopXMLString . "</Result>";
    $stopXMLString = $stopXMLString . "</Address>";
    return $stopXMLString;
}
Example #2
0
function getData($startStop, $endStop, $startDistance, $endDistance)
{
    $showOnlyIndirectRoutes = 1;
    // find out the buses that pass through these stops
    $checkString = findDistanceBetweenSourceDestination($startStop, $endStop);
    $arr = array();
    $arr = split(":", $checkString);
    $strRoute1 = '';
    $strRoute2 = '';
    $strRoute3 = '';
    $strRoute4 = '';
    $minimalDistanceOption7 = 10000;
    $minimalDistanceOption8 = 10000;
    //print_r($arr);
    if ($arr[4] < 0.7) {
        $strRoute = '';
        $routeDetails = htmlentities($startStop) . ":" . $arr[0] . ":" . $arr[1] . ":" . htmlentities($endStop) . ":" . $arr[2] . ":" . $arr[3] . ":" . $arr[4];
        //$st='sdsd';
        $strRoute = '<Routes>';
        $strRoute = $strRoute . '<Route>';
        $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
        $strRoute = $strRoute . '<ErrorCode>5</ErrorCode>';
        $strRoute = $strRoute . '<RouteDetails>' . $routeDetails . '</RouteDetails>';
        $strRoute = $strRoute . '</Route>';
        $strRoute = $strRoute . '</Routes>';
        return $strRoute;
        //echo "The distance is walkable";
    } else {
        $startBuses = explode(",", getBusesForStopWithFrequency($startStop));
        $endBuses = explode(",", getBusesForStopWithFrequency($endStop));
        //print_r($startBuses);
        //print_r($endBuses);
        // for now pick the first entry as the bus number but we need to do some optimization on choosing the buses based on their frequency, the stop number etc
        //$arrCommonBuses=getCommonBuses($startBuses,$endBuses,$showOnlyIndirectRoutes);
        // print_r($arrCommonBuses);
        //echo getJunctionsForIndirectBuses($arrCommonBuses,$startStop,$endStop,$startDistance,$endDistance);
        $status = getJunctionsForIndirectBusesRevamp3($startStop, $endStop, $startBuses, $endBuses, $startDistance, $endDistance, 0);
        //echo "normal status".$status."<br/>";
        // this should not be the case now but just for the sake of eror handling
        if ($status == "404" || $status == "405") {
            list($endStopDepotName, $endStopDepotDistance) = explode(":", getDepotName($endStop));
            list($startStopDepotName, $startStopDepotDistance) = explode(":", getDepotName($startStop));
            $startStopStartDepotDistance = $startStopDepotDistance;
            $endDepotEndStopDistance = $endStopDepotDistance;
            // echo "StartStop=>".$startStop.":".$startStopDepotName.",".$startStopDepotDistance."<br/>EndStop=>".$endStop.":".$endStopDepotName.",".$endStopDepotDistance;
            $totalDistanceForCase1 = 10000;
            $totalDistanceForCase2 = 10000;
            // intension is that it is possible to take only one detour, starting from the start depot
            if ($startStopDepotDistance < (double) 7) {
                //get the direct buses between the startStop and depot
                //echo "first case";
                //find direct bus between start stop and start depot + distance
                $startStopStartDepotCommonBuses = getBusesCommonBetweenTwoStops($startStop, $startStopDepotName);
                if (sizeof($startStopStartDepotCommonBuses) > 0) {
                    $startStopStartDepotDistance = $startStopDepotDistance;
                    $startDepotEndStopCommonBuses = getBusesCommonBetweenTwoStops($startStopDepotName, $endStop);
                    //print_r($startDepotEndStopCommonBuses);
                    //echo sizeof($startDepotEndStopCommonBuses);
                    if (sizeof($startDepotEndStopCommonBuses) > 0) {
                        $startDepotEndStopDistance = distanceBetweenStops($startStopDepotName, $endStop);
                        $totalDistanceForCase1 = $startDistance + $startStopStartDepotDistance + $startDepotEndStopDistance + $endDistance;
                        $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . " We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
                        $strRoute1 = '<Routes>';
                        $strRoute1 = $strRoute1 . '<Route>';
                        $strRoute1 = $strRoute1 . '<IsDirectRoute>N</IsDirectRoute>';
                        $strRoute1 = $strRoute1 . '<ErrorCode>7</ErrorCode>';
                        $strRoute1 = $strRoute1 . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                        $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                        $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                        $routeDetail = $routeDetail . "<Depot>" . htmlentities($startStopDepotName) . ":" . getLatitudeLongitude($startStopDepotName) . ":" . getBusesForStop($startStopDepotName) . "</Depot>";
                        $routeDetail = $routeDetail . "<BusesStartStopAndDepot>" . implode(",", $startStopStartDepotCommonBuses) . "</BusesStartStopAndDepot>";
                        $routeDetail = $routeDetail . "<BusesEndStopAndDepot>" . implode(",", $startDepotEndStopCommonBuses) . "</BusesEndStopAndDepot>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndStartStop>" . $startStopStartDepotDistance . "</DistanceBetweenDepotAndStartStop>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndEndStop>" . $startDepotEndStopDistance . "</DistanceBetweenDepotAndEndStop>";
                        $routeDetail = $routeDetail . "<TotalRouteDistance>" . $totalDistanceForCase1 . "</TotalRouteDistance>";
                        $routeDetail = $routeDetail . "<UseDepot>1</UseDepot>";
                        $strRoute1 = $strRoute1 . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        $strRoute1 = $strRoute1 . '</Route>';
                        $strRoute1 = $strRoute1 . '</Routes>';
                        // echo $strRoute1;
                    }
                }
            }
            // check if the detour is from the endpoint side
            //2. possible to have startStop->EndDepot->endpoint using Bus1, Bus2
            if ($endStopDepotDistance < (double) 7) {
                //echo "second case";
                //find the direct bus between start stop and end depot +distance
                $startStopEndDepotCommonBuses = getBusesCommonBetweenTwoStops($startStop, $endStopDepotName);
                //print_r($startStopEndDepotCommonBuses);
                if (sizeof($startStopEndDepotCommonBuses) > 0) {
                    //echo "first condifition";
                    $startStopEndDepotDistance = distanceBetweenStops($startStop, $endStopDepotName);
                    $endDepotEndStopCommonBuses = getBusesCommonBetweenTwoStops($endStopDepotName, $endStop);
                    if (sizeof($endDepotEndStopCommonBuses) > 0) {
                        //find the direct bus between end depot and the end stop + distnace
                        $endDepotEndStopDistance = $endStopDepotDistance;
                        $totalDistanceForCase2 = $startDistance + $startStopEndDepotDistance + $endDepotEndStopDistance + $endDistance;
                        $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . ". We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
                        $strRoute2 = '<Routes>';
                        $strRoute2 = $strRoute2 . '<Route>';
                        $strRoute2 = $strRoute2 . '<IsDirectRoute>N</IsDirectRoute>';
                        $strRoute2 = $strRoute2 . '<ErrorCode>8</ErrorCode>';
                        $strRoute2 = $strRoute2 . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                        $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                        $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                        $routeDetail = $routeDetail . "<Depot>" . htmlentities($endStopDepotName) . ":" . getLatitudeLongitude($endStopDepotName) . ":" . getBusesForStop($endStopDepotName) . "</Depot>";
                        $routeDetail = $routeDetail . "<BusesStartStopAndDepot>" . implode(",", $startStopEndDepotCommonBuses) . "</BusesStartStopAndDepot>";
                        $routeDetail = $routeDetail . "<BusesEndStopAndDepot>" . implode(",", $endDepotEndStopCommonBuses) . "</BusesEndStopAndDepot>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndStartStop>" . $startStopEndDepotDistance . "</DistanceBetweenDepotAndStartStop>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndEndStop>" . $endDepotEndStopDistance . "</DistanceBetweenDepotAndEndStop>";
                        $routeDetail = $routeDetail . "<TotalRouteDistance>" . $totalDistanceForCase2 . "</TotalRouteDistance>";
                        $routeDetail = $routeDetail . "<UseDepot>1</UseDepot>";
                        $strRoute2 = $strRoute2 . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        $strRoute2 = $strRoute2 . '</Route>';
                        $strRoute2 = $strRoute2 . '</Routes>';
                    }
                }
            }
            //echo "tt".$totalDistanceForCase1.",".$totalDistanceForCase2;
            if ($totalDistanceForCase1 > $totalDistanceForCase2) {
                return $strRoute2;
            } else {
                if ($totalDistanceForCase1 < $totalDistanceForCase2) {
                    return $strRoute1;
                }
            }
            // if both the start poit detour and the endpoint detour failed that means you dont have the buses either from the
            // detour to the endpoint or between the start point and the detour
            if ($totalDistanceForCase1 == 10000 && $totalDistanceForCase2 == 10000) {
                if ($startStopDepotDistance < (double) 7) {
                    //echo "hi";
                    $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . ". We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
                    $startStopStartDepotCommonBuses = getBusesCommonBetweenTwoStops($startStop, $startStopDepotName);
                    $strRoute3 = '<Routes>';
                    //$strRoute2=$strRoute2.'<Route>';
                    $strRoute3 = $strRoute3 . '<IsDirectRoute>N</IsDirectRoute>';
                    $strRoute3 = $strRoute3 . '<ErrorCode>9</ErrorCode>';
                    $strRoute3 = $strRoute3 . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                    $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                    $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                    $routeDetail = $routeDetail . "<Depot>" . htmlentities($startStopDepotName) . ":" . getLatitudeLongitude($startStopDepotName) . ":" . getBusesForStop($startStopDepotName) . "</Depot>";
                    $routeDetail = $routeDetail . "<BusesBetweenStopAndDepot>" . implode(",", $startStopStartDepotCommonBuses) . "</BusesBetweenStopAndDepot>";
                    $routeDetail = $routeDetail . "<DistanceBetweenDepotAndStop>" . $startStopStartDepotDistance . "</DistanceBetweenDepotAndStop>";
                    //  echo "==================";
                    $startDepotBuses = explode(",", getBusesForStopWithFrequency($startStopDepotName));
                    $totalDistanceBeforeReachingToDepot = $startDistance + $startStopStartDepotDistance;
                    $indirectRoutesDetails = getJunctionsForIndirectBusesRevamp3($startStopDepotName, $endStop, $startDepotBuses, $endBuses, 0, $endDistance, $showOnlyIndirectRoutes, 1, $totalDistanceBeforeReachingToDepot);
                    if ($indirectRoutesDetails != "404" && $indirectRoutesDetails != "405") {
                        list($indirectBusesBetweenDepotAndEndpoint, $minimalDistanceOption7) = explode("^", $indirectRoutesDetails);
                        $routeDetail = $routeDetail . "<indirectRoutes>" . $indirectBusesBetweenDepotAndEndpoint . "</indirectRoutes>";
                        //$routeDetail=$routeDetail."<UseDepot>1</UseDepot>";
                        $strRoute3 = $strRoute3 . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        //$strRoute2=$strRoute2.'</Route>';
                        $strRoute3 = $strRoute3 . '</Routes>';
                        //echo $strRoute3;
                    } else {
                        $minimalDistanceOption7 = 10000;
                    }
                }
                if ($endStopDepotDistance < (double) 7) {
                    $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . ". We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
                    $strRoute4 = '<Routes>';
                    $strRoute4 = $strRoute4 . '<IsDirectRoute>N</IsDirectRoute>';
                    $strRoute4 = $strRoute4 . '<ErrorCode>10</ErrorCode>';
                    $strRoute4 = $strRoute4 . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                    $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                    $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                    $endDepotEndStopCommonBuses = getBusesCommonBetweenTwoStops($endStopDepotName, $endStop);
                    $routeDetail = $routeDetail . "<Depot>" . htmlentities($endStopDepotName) . ":" . getLatitudeLongitude($endStopDepotName) . ":" . getBusesForStop($endStopDepotName) . "</Depot>";
                    $routeDetail = $routeDetail . "<BusesBetweenStopAndDepot>" . implode(",", $endDepotEndStopCommonBuses) . "</BusesBetweenStopAndDepot>";
                    $routeDetail = $routeDetail . "<DistanceBetweenDepotAndStop>" . $endDepotEndStopDistance . "</DistanceBetweenDepotAndStop>";
                    //  echo "==================";
                    $endDepotBuses = explode(",", getBusesForStopWithFrequency($endStopDepotName));
                    $totalDistanceBeforeReachingToDepot = $endDistance + $endDepotEndStopDistance;
                    $indirectRoutesDetails = getJunctionsForIndirectBusesRevamp3($startStop, $endStopDepotName, $startBuses, $endDepotBuses, $startDistance, 0, $showOnlyIndirectRoutes, 1, $totalDistanceBeforeReachingToDepot);
                    if ($indirectRoutesDetails != "404" && $indirectRoutesDetails != "405") {
                        list($indirectBusesBetweenDepotAndEndpoint, $minimalDistanceOption8) = explode("^", $indirectRoutesDetails);
                        $routeDetail = $routeDetail . "<indirectRoutes>" . $indirectBusesBetweenDepotAndEndpoint . "</indirectRoutes>";
                        //$routeDetail=$routeDetail."<UseDepot>1</UseDepot>";
                        $strRoute4 = $strRoute4 . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        //$strRoute2=$strRoute2.'</Route>';
                        $strRoute4 = $strRoute4 . '</Routes>';
                        //echo $strRoute3;
                    } else {
                        $minimalDistanceOption8 = 10000;
                    }
                } else {
                    $minimalDistanceOption7 = 10000;
                    $minimalDistanceOption8 = 10000;
                }
            }
            //echo $minimalDistanceOption7.",".$minimalDistanceOption8;
            if ($minimalDistanceOption7 == 10000 && $minimalDistanceOption8 == 10000) {
                //the depots are too far away
                $strRoute = '<Routes>';
                $strRoute = $strRoute . '<Route>';
                $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
                $strRoute = $strRoute . '<ErrorCode>411</ErrorCode>';
                $strRoute = $strRoute . '<StartStop>' . $startStop . '</StartStop>';
                $strRoute = $strRoute . '<EndStop>' . $endStop . '</EndStop>';
                $strRoute = $strRoute . '</Route>';
                $strRoute = $strRoute . '</Routes>';
                return $strRoute;
            } else {
                if ($minimalDistanceOption7 < $minimalDistanceOption8) {
                    return $strRoute3;
                } else {
                    return $strRoute4;
                }
            }
        } else {
            $strRoute = '<Routes>' . $status . '</Routes>';
            return $strRoute;
        }
    }
    //echo "<sample>hhhh</sample>";
}
Example #3
0
/**
The xml should be
<Address>
<Value></Value>
<Info></Info>
<Stops>
<Stop>
<Name></Name>
<Latitude></Latitude>
<Longitude></Longitude>
<Distance></Distance>
<Buses></Buses>
</Stop>
.
.
</Stops>
<Result>
<BusStop></BusStop>
<BusStopLatitude></BusStopLatitude>
<BusStopLongitude></BusStopLongitude>
<Offset></Offset>
</Result>
</Address>
**/
function getStopForAddress($addr, $log)
{
    //echo $addr;
    $stopDataString = '';
    $originalRequestedLatitude = 0;
    $originalRequestedLongitude = 0;
    // create a xml string
    $stopXMLString = '<Address>';
    $query = "Select StopName, Latitude, Longitude from Stops Where StopName LIKE '" . $addr . "%'";
    $result = mysql_query($query);
    $rowsnum = mysql_num_rows($result);
    if ($rowsnum > 1) {
        if ($DEBUG) {
            echo "more than one stops are found with your search criteria <br/>";
        }
        $log->LogDebug("The address " . $addr . " matches more than one in stops table. taking the first one ");
        $stopXMLString = $stopXMLString . "<Info>More than one stops are found with your search criteria</Info>";
        $stopXMLString = $stopXMLString . "<ErrorCode>MS</ErrorCode>";
        $stopXMLString = $stopXMLString . "<Stops>";
        // this is the case wehre we can check which is the best choice in terms of buses coming thourgh..E.g. Marathahalli
        $maxBus = 0;
        for ($i = 0; $i < $rowsnum; $i++) {
            $row = mysql_fetch_row($result);
            $stopXMLString = $stopXMLString . "<Stop>";
            if ($DEBUG) {
                echo $row[0] . "<br/>";
            }
            $stopXMLString = $stopXMLString . "<Name>" . htmlentities($row[0]) . "</Name>";
            $stopXMLString = $stopXMLString . "<Latitude>" . $row[1] . "</Latitude>";
            $stopXMLString = $stopXMLString . "<Longitude>" . $row[2] . "</Longitude>";
            $stopXMLString = $stopXMLString . "<Distance>-1</Distance>";
            $stopXMLString = $stopXMLString . "<Buses>" . getBusesForStop($row[0]) . "</Buses>";
            // $stopDetails=$row[0];
            //$map->addMarkerByCoords($row[2],$row[1],$row[0],getBusesForStop($row[0]),'');
            $NumberOfBus = getNumberOfBusesForStop($row[0]);
            if ($NumberOfBus > $maxBus) {
                $maxBus = $NumberOfBus;
                $stopDataString = $row[0] . ":" . $row[1] . ":" . $row[2] . ":0";
            }
            $stopXMLString = $stopXMLString . "</Stop>";
        }
        $stopXMLString = $stopXMLString . "</Stops>";
    } else {
        if ($rowsnum == 1) {
            $stopXMLString = $stopXMLString . "<Info>Your address matches the correct stop name</Info>";
            $stopXMLString = $stopXMLString . "<ErrorCode>OS</ErrorCode>";
            $stopXMLString = $stopXMLString . "<Stops>";
            $stopXMLString = $stopXMLString . "<Stop>";
            $row = mysql_fetch_row($result);
            if ($DEBUG) {
                echo " Your stop is " . $row[0] . "<br/>";
            }
            $log->LogDebug("The address " . $addr . " is a valid stopname ");
            $stopXMLString = $stopXMLString . "<Name>" . htmlentities($row[0]) . "</Name>";
            $stopXMLString = $stopXMLString . "<Latitude>" . $row[1] . "</Latitude>";
            $stopXMLString = $stopXMLString . "<Longitude>" . $row[2] . "</Longitude>";
            $stopXMLString = $stopXMLString . "<Distance>-1</Distance>";
            $stopXMLString = $stopXMLString . "<Buses>" . getBusesForStop($row[0]) . "</Buses>";
            $stopXMLString = $stopXMLString . "</Stop>";
            // $map->addMarkerByCoords($row[2],$row[1],$row[0],getBusesForStop($row[0]),'');
            $stopDataString = $row[0] . ":" . $row[1] . ":" . $row[2] . ":0";
            $stopXMLString = $stopXMLString . "</Stops>";
        } else {
            if ($rowsnum == 0) {
                //echo "going to the roads database"."<br/>";
                // Checking in the road database
                $query = "Select * from RoadAddresses Where Address ='" . $addr . "'";
                $result = mysql_query($query);
                $rowsnum = mysql_num_rows($result);
                if ($rowsnum == 0) {
                    if ($DEBUG) {
                        echo "The address not found in the database so fetching from internet <br/>";
                    }
                    //$stopXMLString=$stopXMLString."<Info>The address ".$addr." not found in the database so fetching from internet</Info>";
                    $log->LogDebug("The address " . $addr . " not found in the database so fetching from internet ");
                    // fimd from the net
                    $addressString = "http://maps.google.com/maps/api/geocode/json?address=" . urlencode($addr) . ",+Bangalore,+Karnataka,+India&sensor=false";
                    $geocode = file_get_contents($addressString);
                    //echo $geocode;
                    $formattedAddress = return_between($geocode, "formatted_address", "\",", EXCL);
                    $formattedAddressNoiseRemoved = return_between($formattedAddress, ":", "India", INCL);
                    $place = substr($formattedAddressNoiseRemoved, 3);
                    //	echo $place."<br/>";
                    ///echo $place."<br/>";
                    $arr = array();
                    $arr = split(",", $place);
                    if (strcmp(trim($arr[0]), "Bengaluru") == 0 && strcmp(trim($arr[1]), "Karnataka") == 0 && strcmp(trim($arr[2]), "India") == 0) {
                        $stopXMLString = $stopXMLString . "<Info>Address is not valid</Info>";
                        $stopXMLString = $stopXMLString . "<ErrorCode>AM</ErrorCode>";
                        $stopXMLString = $stopXMLString . "<Stops>";
                        $stopXMLString = $stopXMLString . "<Stop>";
                        $stopXMLString = $stopXMLString . "</Stop>";
                        $stopXMLString = $stopXMLString . "</Stops>";
                        if ($DEBUG) {
                            echo "<h3>" . trim($roadName) . "  Address is not valid" . "</h3><br/>";
                        }
                        $stopDataString = "0:0:0:0";
                    } else {
                        $locations = return_between($geocode, "location", "}", EXCL);
                        //echo $locations;
                        $latitude = return_between($locations, "lat\"", ",", EXCL);
                        $latitude = substr($latitude, 3);
                        //echo $latitude;
                        list($lat, $long) = split(",", $locations);
                        list($cap, $val) = split(":", $long);
                        //echo trim($val);
                        $addrLat = trim($latitude);
                        $addrLong = trim($val);
                        $originalRequestedLatitude = $addrLat;
                        $originalRequestedLongitude = $addrLong;
                        // add the marker for the searched address
                        //$map->addMarkerIcon("marker_star.png","marker_shadow.png",15,29,15,3);
                        //$map->addMarkerByCoords($addrLong,$addrLat,$addr,'','');
                        $query = "SELECT  StopName, Latitude, Longitude FROM Stops WHERE (Latitude - " . $addrLat . " < .009) AND (Latitude - " . $addrLat . " > - .009) AND (Longitude - " . $addrLong . " > - .009) AND (Longitude - " . $addrLong . " < 0.009)";
                        //echo $query."<br/>";
                        $result = mysql_query($query);
                        $rowsnum = mysql_num_rows($result);
                        if ($rowsnum == 0) {
                            // this is the case when you gave an address that even could not be found usign the internet search
                            $stopXMLString = $stopXMLString . "<Info>Address is not valid</Info>";
                            $stopXMLString = $stopXMLString . "<ErrorCode>AM</ErrorCode>";
                            $stopXMLString = $stopXMLString . "<Stops>";
                            $stopXMLString = $stopXMLString . "<Stop>";
                            $stopXMLString = $stopXMLString . "</Stop>";
                            $stopXMLString = $stopXMLString . "</Stops>";
                            if ($DEBUG) {
                                echo "<h3>" . trim($roadName) . "  Address is not valid" . "</h3><br/>";
                            }
                            $stopDataString = "0:0:0:0";
                        } else {
                            $arrBusStops = array();
                            for ($i = 0; $i < $rowsnum; $i++) {
                                $row = mysql_fetch_row($result);
                                //echo $row[0];
                                $dist = distance($addrLat, $addrLong, $row[1], $row[2], "K");
                                $BDS = new BusDataStructure($row[0], $row[1], $row[2], $dist);
                                array_push($arrBusStops, $BDS);
                                //echo distance($addrLat, $addrLong, $row[1],$row[2], "K") . " kilometers<br>";
                                //$map->addMarkerByCoords($row[2],$row[1],$row[0].distance($addrLat, $addrLong, $row[1],$row[2], "K"),'','');
                            }
                            // now do the comparison of the data
                            $tempSortedArray = BubbleSort($arrBusStops, $rowsnum);
                            // this is the place to do One more level of filtering based on the number of buses
                            $sortedArray = applyFilterForAddress($tempSortedArray);
                            //print_r($sortedArray);
                            $stopXMLString = $stopXMLString . "<Info>Address Found via Internet</Info>";
                            $stopXMLString = $stopXMLString . "<ErrorCode>IA</ErrorCode>";
                            $stopXMLString = $stopXMLString . "<Stops>";
                            for ($i = 0; $i < sizeof($sortedArray); $i++) {
                                //echo $sortedArray[$i]->getStopName().$sortedArray[$i]->getDistance()."<br/>";
                                $stopXMLString = $stopXMLString . "<Stop>";
                                //$map->addMarkerByCoords($sortedArray[$i]->getLongitude(),$sortedArray[$i]->getLatitude(),$sortedArray[$i]->getStopName().$sortedArray[$i]->getDistance(),getBusesForStop($sortedArray[$i]->getStopName()),'');
                                $stopXMLString = $stopXMLString . "<Name>" . htmlentities($sortedArray[$i]->getStopName()) . "</Name>";
                                $stopXMLString = $stopXMLString . "<Latitude>" . $sortedArray[$i]->getLatitude() . "</Latitude>";
                                $stopXMLString = $stopXMLString . "<Longitude>" . $sortedArray[$i]->getLongitude() . "</Longitude>";
                                $stopXMLString = $stopXMLString . "<Distance>" . $sortedArray[$i]->getDistance() . "</Distance>";
                                $stopXMLString = $stopXMLString . "<Buses>" . getBusesForStop($sortedArray[$i]->getStopName()) . "</Buses>";
                                $stopXMLString = $stopXMLString . "</Stop>";
                            }
                            $stopXMLString = $stopXMLString . "</Stops>";
                            $stopDataString = $sortedArray[0]->getStopName() . ":" . $sortedArray[0]->getLatitude() . ":" . $sortedArray[0]->getLongitude() . ":" . $sortedArray[0]->getDistance();
                        }
                    }
                } else {
                    if ($rowsnum > 1) {
                        $stopXMLString = $stopXMLString . "<Info>More than one matching address found in road database. Kindly add some more specifics</Info>";
                        $stopXMLString = $stopXMLString . "<ErrorCode>MA</ErrorCode>";
                        $stopXMLString = $stopXMLString . "<Stops>";
                        $stopXMLString = $stopXMLString . "<Stop>";
                        $stopXMLString = $stopXMLString . "</Stop>";
                        $stopXMLString = $stopXMLString . "</Stops>";
                        if ($DEBUG) {
                            echo "More than one matching address found in road database. Kindly add some more specifics";
                        }
                        $stopDataString = "m:m:m:m";
                    } else {
                        if ($DEBUG) {
                            echo "Found in the road database" . "<br/>";
                        }
                        $log->LogDebug("The address " . $addr . " found in the road database ");
                        $row = mysql_fetch_row($result);
                        $addrLat = $row[3];
                        $addrLong = $row[4];
                        $originalRequestedLatitude = $addrLat;
                        $originalRequestedLongitude = $addrLong;
                        //echo $addrLat;
                        //$map->addMarkerByCoords($addrLong,$addrLat,$addr,'','');
                        $query = "SELECT  StopName, Latitude, Longitude FROM Stops WHERE (Latitude - " . $addrLat . " < .009) AND (Latitude - " . $addrLat . " > - .009) AND (Longitude - " . $addrLong . " > - .009) AND (Longitude - " . $addrLong . " < 0.009)";
                        //echo $query."<br/>";
                        $result = mysql_query($query);
                        $rowsnum = mysql_num_rows($result);
                        if ($rowsnum == 0) {
                            $stopXMLString = $stopXMLString . "<Info>All stops are more then 1 km far</Info>";
                            $stopXMLString = $stopXMLString . "<ErrorCode>KM</ErrorCode>";
                            $stopXMLString = $stopXMLString . "<Stops>";
                            $stopXMLString = $stopXMLString . "<Stop>";
                            $stopXMLString = $stopXMLString . "</Stop>";
                            $stopXMLString = $stopXMLString . "</Stops>";
                            //echo "All stops are more then 1 km far";
                        } else {
                            // we should try to show nearest 5 at the max
                            // one way is to create a array of datastructure and then sort them on the basis of distance.
                            // also find the buses for the finalised stops
                            $arrBusStops = array();
                            $stopXMLString = $stopXMLString . "<Info>Address Found in the Road Database</Info>";
                            $stopXMLString = $stopXMLString . "<ErrorCode>RA</ErrorCode>";
                            for ($i = 0; $i < $rowsnum; $i++) {
                                $row = mysql_fetch_row($result);
                                $dist = distance($addrLat, $addrLong, $row[1], $row[2], "K");
                                $BDS = new BusDataStructure($row[0], $row[1], $row[2], $dist);
                                array_push($arrBusStops, $BDS);
                            }
                            // now do the comparison of the data
                            $tempSortedArray = BubbleSort($arrBusStops, $rowsnum);
                            // this is the place to do One more level of filtering based on the number of buses
                            $sortedArray = applyFilterForAddress($tempSortedArray);
                            //print_r($sortedArray);
                            $stopXMLString = $stopXMLString . "<Stops>";
                            for ($i = 0; $i < sizeof($sortedArray); $i++) {
                                //echo $sortedArray[$i]->getStopName().$sortedArray[$i]->getDistance()."<br/>";
                                $stopXMLString = $stopXMLString . "<Stop>";
                                //$map->addMarkerByCoords($sortedArray[$i]->getLongitude(),$sortedArray[$i]->getLatitude(),$sortedArray[$i]->getStopName().$sortedArray[$i]->getDistance(),getBusesForStop($sortedArray[$i]->getStopName()),'');
                                $stopXMLString = $stopXMLString . "<Name>" . htmlentities($sortedArray[$i]->getStopName()) . "</Name>";
                                $stopXMLString = $stopXMLString . "<Latitude>" . $sortedArray[$i]->getLatitude() . "</Latitude>";
                                $stopXMLString = $stopXMLString . "<Longitude>" . $sortedArray[$i]->getLongitude() . "</Longitude>";
                                $stopXMLString = $stopXMLString . "<Distance>" . $sortedArray[$i]->getDistance() . "</Distance>";
                                $stopXMLString = $stopXMLString . "<Buses>" . getBusesForStop($sortedArray[$i]->getStopName()) . "</Buses>";
                                $stopXMLString = $stopXMLString . "</Stop>";
                            }
                            $stopXMLString = $stopXMLString . "</Stops>";
                            $stopDataString = $sortedArray[0]->getStopName() . ":" . $sortedArray[0]->getLatitude() . ":" . $sortedArray[0]->getLongitude() . ":" . $sortedArray[0]->getDistance();
                        }
                    }
                }
            }
        }
    }
    $stopXMLString = $stopXMLString . "<Result>";
    list($BusStop, $BusLatitude, $BusLongitude, $BusOffset) = split(":", $stopDataString);
    $stopXMLString = $stopXMLString . "<BusStop>" . htmlentities($BusStop) . "</BusStop>";
    $stopXMLString = $stopXMLString . "<BusStopLatitude>" . $BusLatitude . "</BusStopLatitude>";
    $stopXMLString = $stopXMLString . "<BusStopLongitude>" . $BusLongitude . "</BusStopLongitude>";
    $stopXMLString = $stopXMLString . "<Offset>" . $BusOffset . "</Offset>";
    $stopXMLString = $stopXMLString . "<Buses>" . getBusesForStop($BusStop) . "</Buses>";
    $stopXMLString = $stopXMLString . "<OriginalStopLatitude>" . $originalRequestedLatitude . "</OriginalStopLatitude>";
    $stopXMLString = $stopXMLString . "<OriginalStopLongitude>" . $originalRequestedLongitude . "</OriginalStopLongitude>";
    $stopXMLString = $stopXMLString . "</Result>";
    $stopXMLString = $stopXMLString . "</Address>";
    return $stopXMLString;
}
Example #4
0
						
						if(sizeof($endDepotEndStopCommonBuses)>0)
						{
							//find the direct bus between end depot and the end stop + distnace
							$endDepotEndStopDistance=$endStopDepotDistance;
							$totalDistanceForCase2=$startDistance+$startStopEndDepotDistance+$endDepotEndStopDistance+$endDistance;
							$routeInfoString="There is no direct or indirect bus availalble between ".$startStop." and ".$endStop.". We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
							
							$strRoute2='<Routes>';
							 $strRoute2=$strRoute2.'<Route>';
							 $strRoute2=$strRoute2.'<IsDirectRoute>N</IsDirectRoute>';
							 $strRoute2=$strRoute2.'<ErrorCode>8</ErrorCode>';
							 $strRoute2=$strRoute2."<RouteInfo>".$routeInfoString."</RouteInfo>";							
							 $routeDetail="<StartStop>".htmlentities($startStop)."</StartStop>";
							 $routeDetail=$routeDetail."<EndStop>".htmlentities($endStop)."</EndStop>";
							 $routeDetail=$routeDetail."<Depot>".htmlentities($endStopDepotName).":".getLatitudeLongitude($endStopDepotName).":".getBusesForStop($endStopDepotName)."</Depot>";
							 $routeDetail=$routeDetail."<BusesStartStopAndDepot>".implode(",",$startStopEndDepotCommonBuses)."</BusesStartStopAndDepot>";
							 $routeDetail=$routeDetail."<BusesEndStopAndDepot>".implode(",",$endDepotEndStopCommonBuses)."</BusesEndStopAndDepot>";							 
							 $routeDetail=$routeDetail."<DistanceBetweenDepotAndStartStop>".$startStopEndDepotDistance."</DistanceBetweenDepotAndStartStop>";
							 $routeDetail=$routeDetail."<DistanceBetweenDepotAndEndStop>".$endDepotEndStopDistance."</DistanceBetweenDepotAndEndStop>";
							 $routeDetail=$routeDetail."<TotalRouteDistance>".$totalDistanceForCase2."</TotalRouteDistance>";
							 $routeDetail=$routeDetail."<UseDepot>1</UseDepot>";
							 $strRoute2=$strRoute2.'<RouteDetails>'.$routeDetail.'</RouteDetails>';
							 $strRoute2=$strRoute2.'</Route>';
							 $strRoute2=$strRoute2.'</Routes>';

							// echo $strRoute2;
						}					
					}
				}
Example #5
0
    $arr = array();
    $arr = split(":", $checkString);
    //print_r($arr);
    if ($arr[4] < 0.7) {
        $strRoute = '';
        $routeDetails = htmlentities($startStop) . ":" . $arr[0] . ":" . $arr[1] . ":" . htmlentities($endStop) . ":" . $arr[2] . ":" . $arr[3] . ":" . $arr[4];
        //$st='sdsd';
        $strRoute = '<Routes>';
        $strRoute = $strRoute . '<Route>';
        $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
        $strRoute = $strRoute . '<ErrorCode>5</ErrorCode>';
        $strRoute = $strRoute . '<RouteDetails>' . $routeDetails . '</RouteDetails>';
        $strRoute = $strRoute . '</Route>';
        $strRoute = $strRoute . '</Routes>';
        echo $strRoute;
        //echo "The distance is walkable";
    } else {
        $startBuses = split(",", getBusesForStop($startStop));
        $endBuses = split(",", getBusesForStop($endStop));
        //print_r($startBuses);
        //print_r($endBuses);
        // for now pick the first entry as the bus number but we need to do some optimization on choosing the buses based on their frequency, the stop number etc
        $arrCommonBuses = getCommonBuses($startBuses, $endBuses, $showOnlyIndirectRoutes);
        // print_r($arrCommonBuses);
        echo getJunctionsForIndirectBuses($arrCommonBuses, $startStop, $endStop, $startDistance, $endDistance);
    }
    //echo "<sample>hhhh</sample>";
}
?>

/**
* This is a special function for the depots.
* This needs to return the direct or indirect buses between the two depots
* Important thing is to finalize on the structure of the xml that will be returned.
* This will return only a subpart of the xml
* the structure in case of direct bus found between the depots the structure will be
*<Routes>
	<Route>
		<IsDirectRoute />
		<ErrorCode>9</ErrorCode>
		<IsDirectBusesBwDepots>Y</IsDirectBusesBwDepots>
		<RouteInfo />
		<StartStop/>
		<EndStop/>
		<FirstDepotNames />
		<SecondDepotName />
		<BusesStartStopAndDepot />
		<BusesInterDepot />
		<BusesEndStopAndDepot />
		<DistanceBetweenStartStopAndFirstDepot />
		<DistanceBetweenDepots />
		<DistanceBetweenEndStopAndLastDepot />
		<TotalRouteDistance />
		<UseDepot />
	</Route>
</Routes>
*
* In this case the user will be given 3 buses 
*the structure in case of indirect buses found the structure will be
*<Routes>
	<Route>
		<IsDirectRoute />
		<ErrorCode>10</ErrorCode>
		<IsDirectBusesBwDepots>N</IsDirectBusesBwDepots>
		<RouteInfo />
		<StartStop/>
		<EndStop/>
		<FirstDepotNames />
		<SecondDepotName />
		<BusesStartStopAndDepot />
		<BusesInterDepot> {for loop..we need to remove the cases where there are two junctions}
		   <BusesFirstDepotAndJunction></BusesFirstDepotAndJunction>
		   <JunctionName></JunctionName>
		   <BusesSecondDepotAndJunction></BusesSecondDepotAndJunction>
		   <DistanceBetweenFirstDepotAndJunction />
		   <DistanceBetweenSecondDepotAndJunction />		
		</BusesInterDepot>
		<BusesEndStopAndDepot />
		<DistanceBetweenStartStopAndFirstDepot />
		<DistanceBetweenEndStopAndLastDepot />
		<StartStopOffset />
		<EndSopOffset/>
		<UseDepot />
	</Route>
</Routes>
* Note: in this case we will end up in 4 buses. I think that is too much but will show this
* The errror condition and invealid search will give 407 & 408 respectively we will display the errorr that nothing could be found
* startDepotStop : this is the first depot
* endDepotStop: This is the second depot
* startDepotBuses : this is the set of buses which goes to first depot
* endDepotBuses: this is the set of buses that goes to the second depot
* startStopStartDepotCommonBusesString: these are the buses that goes between the start stop and the startdepot
* endDepotEndStopCommonBusesString : these are the buses that are common between the end stop and the end depot
* startOffsetDistance: This is the offest distacne between the source and the start stop. Here used to calculate the total distance
* endOffsetDistance: This is the offset distance between the end point and the destnatiuon. here used to calculate the total distance
* distanceBetweenStartStopAndFirstDepot: The distance between the start stop an dthe first depot
* distanceBetweenEndStopAndLastDepot : The distcnae between the end point and the last depot
*/
function getJunctionsForInterDepotTravel($startStop, $endStop, $startDepotStop, $endDepotStop, $startDepotBuses, $endDepotBuses, $startOffsetDistance, $endOffsetDistance, $startStopStartDepotCommonBusesString, $endDepotEndStopCommonBusesString, $distanceBetweenStartStopAndFirstDepot, $distanceBetweenEndStopAndLastDepot, $showOnlyIndirectBuses)
{
    //echo "ddd";
    //get the buses that are direct
    // actually the arrays have the last entry as null so 1 less
    $arrSameBus = array();
    //  print_r($startBuses);
    $numStartBuses = sizeof($startDepotBuses);
    //print_r($endBuses);
    for ($ii = 0; $ii < $numStartBuses; $ii++) {
        $tempStart = $startDepotBuses[$ii];
        // this checks is the same bus is available in the start buses and end buses.
        if (in_array($tempStart, $endDepotBuses)) {
            $element = $tempStart . ":" . $tempStart;
            array_push($arrSameBus, $element);
        }
    }
    // print_r($arrSameBus);
    $sortedDirectBuses = array();
    //sort all the direct buses on the basis of frequency and distance of the route. Also see if the direct bus is not a BIAs
    if (sizeof($arrSameBus) > 0 && $showOnlyIndirectBuses == 0) {
        $directDistance = getDirectBusDistance($startDepotStop, $endDepotStop, 0, 0);
        // $sortedDirectBuses=sortBusesBasedOnDistanceToDestination($arrSameBus);
        $sortedDirectBuses = sortBasedOnBusFrequency($arrSameBus);
        // at this point we can sort it out based on the frequency of the buses and also let the know the meaning of the frequency
        $sortedDirectBuses = applyBIAFilter($sortedDirectBuses);
        //echo "found the direct buses";
        //return displayDirectBuses($sortedDirectBuses,$directDistance);
        //need to return a sub xml in this place.
        $distanceBetweenDepots = distanceBetweenStops($startDepotStop, $endDepotStop);
        $totalRouteDistance = $startOffsetDistance + $distanceBetweenStartStopAndFirstDepot + $distanceBetweenDepots + $distanceBetweenEndStopAndLastDepot + $endOffsetDistance;
        $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . ". We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
        $routeDetails = "<Routes>";
        $routeDetails = $routeDetails . "<Route>";
        $routeDetails = $routeDetails . "<IsDirectRoute>N</IsDirectRoute>";
        $routeDetails = $routeDetails . "<ErrorCode>9</ErrorCode>";
        //$routeDetails=$routeDetails."<IsDirectBusesBwDepots>Y</IsDirectBusesBwDepots>";
        $routeDetails = $routeDetails . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
        $routeDetails = $routeDetails . "<RouteDetails>";
        $routeDetails = $routeDetails . "<StartStop>" . htmlentities($startStop) . "</StartStop>";
        $routeDetails = $routeDetails . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
        $routeDetails = $routeDetails . "<FirstDepotName>" . htmlentities($startDepotStop) . ":" . getLatitudeLongitude($startDepotStop) . ":" . getBusesForStop($startDepotStop) . "</FirstDepotName>";
        $routeDetails = $routeDetails . "<SecondDepotName>" . htmlentities($endDepotStop) . ":" . getLatitudeLongitude($endDepotStop) . ":" . getBusesForStop($endDepotStop) . "</SecondDepotName>";
        $routeDetails = $routeDetails . "<BusesStartStopAndDepot>" . $startStopStartDepotCommonBusesString . "</BusesStartStopAndDepot>";
        $routeDetails = $routeDetails . "<BusesInterDepot>" . implode(",", $sortedDirectBuses) . "</BusesInterDepot>";
        $routeDetails = $routeDetails . "<BusesEndStopAndDepot>" . $endDepotEndStopCommonBusesString . "</BusesEndStopAndDepot>";
        $routeDetails = $routeDetails . "<DistanceBetweenStartStopAndFirstDepot>" . $distanceBetweenStartStopAndFirstDepot . "</DistanceBetweenStartStopAndFirstDepot>";
        $routeDetails = $routeDetails . "<DistanceBetweenEndStopAndLastDepot>" . $distanceBetweenEndStopAndLastDepot . "</DistanceBetweenEndStopAndLastDepot>";
        $routeDetails = $routeDetails . "<DistanceBetweenDepots>" . $distanceBetweenDepots . "</DistanceBetweenDepots>";
        $routeDetails = $routeDetails . "<TotalRouteDistance>" . $totalRouteDistance . "</TotalRouteDistance>";
        $routeDetails = $routeDetails . "</RouteDetails>";
        $routeDetails = $routeDetails . "</Route>";
        $routeDetails = $routeDetails . "</Routes>";
        return $routeDetails;
    } else {
        $arrFirstJunctions = array();
        $arrSecondJunctions = array();
        $arrFirstBuses = array();
        $arrSecondBuses = array();
        $numEndBuses = sizeof($endDepotBuses);
        $displayJunctionsDataArray = array();
        if ($numStartBuses > 10) {
            $numStartBuses = 10;
        }
        if ($numEndBuses > 10) {
            $numEndBuses = 10;
        }
        for ($i = 0; $i < $numStartBuses; $i++) {
            $firstBus = $startDepotBuses[$i];
            $minimum = 10000;
            for ($j = 0; $j < $numEndBuses; $j++) {
                $secondBus = $endDepotBuses[$j];
                //avoiud the direct bus combination
                if ($firstBus == $secondBus) {
                    continue;
                }
                //echo "secondBus".$secondBus;
                // i think when the first bus is same as the second bus this fails
                //find the entry from the table.
                list($firstBusNumber, $firstBusFrequency, $firstBusStartPoint, $secondBusNumber, $secondBusFrequency, $firstBusLowerJunction, $secondBusLowerJunction, $distLower, $lowerJunctionFrequency, $firstBusHigherJunction, $secondBusHigherJunction, $distHigher, $higherJunctionFrequency) = explode(":", getIntermediateStopsAndDistanceWithFrequency($firstBus, $secondBus));
                //return;
                //need to find which junction is valid for the source stop
                if ($firstBusLowerJunction != $firstBusHigherJunction) {
                    if (distanceBetweenStops($firstBusStartPoint, $firstBusLowerJunction) < distanceBetweenStops($firstBusStartPoint, $firstBusHigherJunction)) {
                        // echo "inside lower <br/>";
                        $junction1 = $firstBusLowerJunction;
                        $junction2 = $secondBusLowerJunction;
                        $junctionFrequency = $lowerJunctionFrequency;
                        $dist = $distLower;
                        $totalRouteDistance = getTotalRouteDistance($startDepotStop, $junction1, $junction2, $dist, $endDepotStop, 0, 0);
                        //echo $totalRouteDistance."<br/>";
                    } else {
                        //echo "inside higher <br/>";
                        $junction1 = $firstBusHigherJunction;
                        $junction2 = $secondBusHigherJunction;
                        $junctionFrequency = $higherJunctionFrequency;
                        $dist = $distHigher;
                        $totalRouteDistance = getTotalRouteDistance($startDepotStop, $junction1, $junction2, $dist, $endDepotStop, 0, 0);
                    }
                } else {
                    //echo "inside common <br/>";
                    $junction1 = $firstBusLowerJunction;
                    $junction2 = $secondBusLowerJunction;
                    $junctionFrequency = $lowerJunctionFrequency;
                    $dist = $distLower;
                    $totalRouteDistance = getTotalRouteDistance($startDepotStop, $junction1, $junction2, $dist, $endDepotStop, 0, 0);
                }
                //echo $dist."<br/>";
                //collective frequency= sum(firstbus frequency, second bus frequency)
                //may be buses are high frequency but the junction are seperataed
                //&& $firstBusFrequency >0 && $secondBusFrequency >0
                if ($dist < (double) 0.8) {
                    // echo "hh".$junction1.",".$junction2."<br/>";
                    //print_r($displayJunctionsDataArray);
                    //echo "<br/>";
                    if (checkUniqueJunctions($displayJunctionsDataArray, $junction1, $junction2, $dist) == 0) {
                        // also chekc that the endstop or the start stop is not same as the juntion as in case of marathahalli bridge and multiplex
                        if (strcmp($junction1, $startDepotStop) == 0 || strcmp($junction1, $endDepotStop) == 0 || strcmp($junction2, $startDepotStop) == 0 || strcmp($junction2, $endDepotStop) == 0) {
                            //echo "in the pit";
                            continue;
                        } else {
                            $junctionString = $junction1 . ":" . $junction2 . ":" . $dist;
                            //echo "distashdg".$dist;
                            //$junctionString,$totalDistance,$startStop,$endStop,$junction1,$junction2,$junctionDistance
                            $element = new DisplaySortedJunctionsData($junctionString, $totalRouteDistance, $startStop, $endStop, $junction1, $junction2, $dist);
                            //echo "element".$i.",".$j."<br/>";
                            //	print_r($element);
                            array_push($displayJunctionsDataArray, $element);
                            //array_push($arrayUniqueJunctions,$element);
                        }
                    }
                }
            }
        }
        $SortedJunctionsDataArray = sortBasedOnTotalRouteDistance($displayJunctionsDataArray);
        // display the results
        $strRoute = '';
        if (sizeof($SortedJunctionsDataArray) == 0 || strlen($SortedJunctionsDataArray[0]->getFirstJunction()) == 0) {
            //echo "inside 409";
            return "409";
        } else {
            $strRoute = '<Routes>';
            // there can be chances that when we are filling the xml all the details are not properly found. In that case we need to
            // remove that entry. If at the end this check counter becomes equals to the sizeof($SortedJunctionsDataArray). It means every entry had a problem
            // and we will return the error code 4
            $FalseAlarmCounter = 0;
            $sizeofSortedJunctions = sizeof($SortedJunctionsDataArray);
            //populate a datastructure
            for ($i = 0; $i < $sizeofSortedJunctions; $i++) {
                list($firstJnName, $secondJnName, $distanceJn) = explode(":", $SortedJunctionsDataArray[$i]->getJunctionString());
                $getCommonBusesForFirstJunctionArray = getBusesCommonBetweenTwoStops($startDepotStop, $firstJnName);
                $getCommonBusesForSecondJunctionArray = getBusesCommonBetweenTwoStops($secondJnName, $endDepotStop);
                $junction1Frequency = sizeof($getCommonBusesForFirstJunctionArray);
                $junction2Frequency = sizeof($getCommonBusesForSecondJunctionArray);
                $getCommonBusesForFirstJunction = implode(",", $getCommonBusesForFirstJunctionArray);
                $getCommonBusesForSecondJunction = implode(",", $getCommonBusesForSecondJunctionArray);
                $SortedJunctionsDataArray[$i]->setFirstJunctionFrequency($junction1Frequency);
                $SortedJunctionsDataArray[$i]->setSecondJunctionFrequency($junction2Frequency);
                $SortedJunctionsDataArray[$i]->setStartBusString($getCommonBusesForFirstJunction);
                $SortedJunctionsDataArray[$i]->setEndBusString($getCommonBusesForSecondJunction);
            }
            $SortedJunctionsDataArray = prioritizeAndSortJunctionArray($SortedJunctionsDataArray);
            $sizeofSortedJunctions = sizeof($SortedJunctionsDataArray);
            $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . ". We have tried to find a route that " . "takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
            //need to see how to create this xml. If needed we can break the bus into seperate sml tags, every element as
            //speerate xml tag
            for ($i = 0; $i < $sizeofSortedJunctions; $i++) {
                $isCorrectEntry = 1;
                // check if this particular entry is correct. Since the node need to be removed otherwise
                if ($i > 2) {
                    // this will restrict the indirect results to 3
                    break;
                }
                //list($firstJnName,$secondJnName,$distanceJn)=explode(":",$SortedJunctionsDataArray[$i]->getJunctionString());
                $firstJnName = $SortedJunctionsDataArray[$i]->getFirstJunction();
                $secondJnName = $SortedJunctionsDataArray[$i]->getSecondJunction();
                $distanceJn = $SortedJunctionsDataArray[$i]->getJunctionDistance();
                $junction1Frequency = $SortedJunctionsDataArray[$i]->getFirstJunctionFrequency();
                $junction2Frequency = $SortedJunctionsDataArray[$i]->getSecondJunctionFrequency();
                //get all the buses for firstJn
                //get all the buses for second jun..
                // if the distance between the two junctions is 0
                if ($distanceJn == 0 && strcmp($firstJnName, $startDepotStop) != 0) {
                    $getCommonBusesForFirstJunction = $SortedJunctionsDataArray[$i]->getStartBusString();
                    //getBusesCommonBetweenTwoStops($startStop,$firstJnName);
                    $getCommonBusesForSecondJunction = $SortedJunctionsDataArray[$i]->getEndBusString();
                    //getBusesCommonBetweenTwoStops($secondJnName,$endStop);
                    if ($junction1Frequency > 0 && $junction2Frequency > 0) {
                        $strRoute = $strRoute . '<Route>';
                        $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
                        $strRoute = $strRoute . '<ErrorCode>10</ErrorCode>';
                        //$strRoute=$strRoute.'<IsDirectBusesBwDepots>N</IsDirectBusesBwDepots>';
                        $strRoute = $strRoute . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                        $routeDetail = '';
                        $routeDetail = $routeDetail . "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                        $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                        $routeDetail = $routeDetail . "<FirstDepotName>" . htmlentities($startDepotStop) . ":" . getLatitudeLongitude($startDepotStop) . ":" . getBusesForStop($startDepotStop) . "</FirstDepotName>";
                        $routeDetail = $routeDetail . "<SecondDepotName>" . htmlentities($endDepotStop) . ":" . getLatitudeLongitude($endDepotStop) . ":" . getBusesForStop($endDepotStop) . "</SecondDepotName>";
                        $routeDetail = $routeDetail . "<BusesStartStopAndDepot>" . $startStopStartDepotCommonBusesString . "</BusesStartStopAndDepot>";
                        $routeDetail = $routeDetail . "<FirstJunction>" . htmlentities($firstJnName) . ":" . getLatitudeLongitude($firstJnName) . ":" . getBusesForStop($firstJnName) . "</FirstJunction>";
                        $routeDetail = $routeDetail . "<DistanceBetweenJunction>0</DistanceBetweenJunction>";
                        $routeDetail = $routeDetail . "<SecondJunction>" . htmlentities($secondJnName) . ":" . getLatitudeLongitude($secondJnName) . ":" . getBusesForStop($secondJnName) . "</SecondJunction>";
                        $routeDetail = $routeDetail . "<BusesStartDepotAndJunction>" . $getCommonBusesForFirstJunction . "</BusesStartDepotAndJunction>";
                        $routeDetail = $routeDetail . "<BusesEndDepotAndJunction>" . $getCommonBusesForSecondJunction . "</BusesEndDepotAndJunction>";
                        $routeDetail = $routeDetail . "<BusesEndStopAndDepot>" . $endDepotEndStopCommonBusesString . "</BusesEndStopAndDepot>";
                        $routeDetail = $routeDetail . "<DistanceBetweenStartStopAndFirstDepot>" . $distanceBetweenStartStopAndFirstDepot . "</DistanceBetweenStartStopAndFirstDepot>";
                        $routeDetail = $routeDetail . "<DistanceBetweenEndStopAndLastDepot>" . $distanceBetweenEndStopAndLastDepot . "</DistanceBetweenEndStopAndLastDepot>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepots>" . $SortedJunctionsDataArray[$i]->getTotalRouteDistance() . "</DistanceBetweenDepots>";
                        $totalDistance = $startOffsetDistance + $distanceBetweenStartStopAndFirstDepot + $SortedJunctionsDataArray[$i]->getTotalRouteDistance() + $distanceBetweenEndStopAndLastDepot + $endOffsetDistance;
                        $routeDetail = $routeDetail . "<TotalDistance>" . $totalDistance . "</TotalDistance>";
                        $routeDetail = $routeDetail . "<UseDepot>" . $useDepot . "</UseDepot>";
                        $strRoute = $strRoute . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        //echo "<hr/>";
                        $strRoute = $strRoute . '</Route>';
                    } else {
                        //echo "False positive";
                        //$strRoute=$strRoute.'<ErrorCode>6</ErrorCode>';
                        $FalseAlarmCounter++;
                    }
                }
                //echo $strRoute;
            }
            $strRoute = $strRoute . '</Routes>';
            // check if every thing was wrong that means we need to send the erro codes.
            if ($FalseAlarmCounter == sizeof($SortedJunctionsDataArray)) {
                /*$strRoute='<Routes>';
                  $strRoute=$strRoute.'<Route>';
                  $strRoute=$strRoute.'<IsDirectRoute>N</IsDirectRoute>';
                  $strRoute=$strRoute.'<ErrorCode>4</ErrorCode>';
                  $strRoute=$strRoute.'</Route>';
                  $strRoute=$strRoute.'</Routes>';
                  */
                //echo "inside 410";
                return "410";
            }
        }
        // echo "---------------------------------<br/>";
        // echo $strRoute;
        return $strRoute;
    }
}
    $arr = array();
    $arr = explode(":", $checkString);
    //print_r($arr);
    if ($arr[4] < 0.7) {
        $strRoute = '';
        $routeDetails = htmlentities($startStop) . ":" . $arr[0] . ":" . $arr[1] . ":" . htmlentities($endStop) . ":" . $arr[2] . ":" . $arr[3] . ":" . $arr[4];
        //$st='sdsd';
        $strRoute = '<Routes>';
        $strRoute = $strRoute . '<Route>';
        $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
        $strRoute = $strRoute . '<ErrorCode>5</ErrorCode>';
        $strRoute = $strRoute . '<RouteDetails>' . $routeDetails . '</RouteDetails>';
        $strRoute = $strRoute . '</Route>';
        $strRoute = $strRoute . '</Routes>';
        echo $strRoute;
        //echo "The distance is walkable";
    } else {
        $startBuses = explode(",", getBusesForStop($startStop));
        $endBuses = explode(",", getBusesForStop($endStop));
        //print_r($startBuses);
        //print_r($endBuses);
        // for now pick the first entry as the bus number but we need to do some optimization on choosing the buses based on their frequency, the stop number etc
        $arrCommonBuses = getCommonBuses($startBuses, $endBuses, $showOnlyIndirectRoutes);
        // print_r($arrCommonBuses);
        echo getJunctionsForIndirectBuses($arrCommonBuses, $startStop, $endStop, $startDistance, $endDistance);
    }
    //echo "<sample>hhhh</sample>";
}
?>