コード例 #1
0
function findS2APath($start_marker, $end_stations, $end)
{
    $debug = false;
    $WALKING_SPEED = 2 / 3600;
    if ($debug) {
        echo "findS2APath<br/>";
    }
    // verify this is a legitimate search
    foreach ($end_stations as $station) {
        if ($station->marker == $start_marker) {
            return "walk";
        }
    }
    // create end marker
    $end_name = $end->name;
    if ($end_name == "") {
        $end_name = $end->getAddressString();
    }
    $end_marker = new Marker($end->point->lat, $end->point->lng, "end", $end_name);
    if ($debug) {
        echo "end marker = ";
        $end_marker->printInfo();
    }
    // create array of paths
    $open = array();
    foreach ($start_marker->getLines() as $line) {
        foreach ($line->getConnections() as $connection) {
            // get associated marker
            $marker = getMarker($connection->id);
            if ($debug) {
                echo "retrieved marker from connection (" . $connection->id . "): ";
                $marker->printInfo();
            }
            $lines = $start_marker->getOverlapLines($marker);
            $segment = new Segment($start_marker, $marker, $lines, $connection->duration, $connection->type);
            $visited = array();
            $visited[] = $start_marker;
            $visited[] = $marker;
            $new_box = new Box($marker->point, $end_marker->point);
            $path = new Path2($segment, $new_box, $visited);
            if ($marker == $end_marker) {
                return $path;
            }
            $area = $new_box->getArea();
            $array = $open["{$area}"];
            if ($array == null) {
                $array = array();
            }
            $array[] = $path;
            $open["{$area}"] = $array;
        }
    }
    return findPath($open, $end_stations, $end_marker);
}
コード例 #2
0
/**
	
	@param $start<Location> the starting location (address)
	@param $end<Location> the ending location (address)
*/
function findDirPath($start, $end, $start_stations, $end_stations)
{
    $debug = false;
    if ($start == $end) {
        return "same";
    }
    if (distance($start, $end) < 0.25) {
        return "walk";
    }
    $WALKING_SPEED = 2 / 3600;
    #echo "findDirPath<br/>";
    // determine original bounding box
    $original_box = new Box($start->point, $end->point);
    // create end marker
    $end_name = $end->name;
    if ($end_name == "") {
        $end_name = $end->getAddressString();
    }
    $end_marker = new Marker($end->point->lat, $end->point->lng, "end", $end_name);
    if ($debug) {
        echo "end marker = ";
        $end_marker->printInfo();
    }
    // create array of paths
    $open = array();
    $start_name = $start->name;
    if ($start_name == "") {
        $start_name = $start->getAddressString();
    }
    $start_marker = new Marker($start->point->lat, $start->point->lng, "start", $start_name);
    if ($debug) {
        echo "start marker = ";
        $start_marker->printInfo();
    }
    foreach ($start_stations as $station) {
        $segment = new Segment($start_marker, $station->marker, $station->marker->lines, $station->getDistance() / $WALKING_SPEED, "walking");
        $visited = array();
        $visited[] = $station->marker;
        $new_box = new Box($station->marker->point, $end_marker->point);
        $path = new Path2($segment, $new_box, $visited);
        $area = $new_box->getArea();
        $array = $open["{$area}"];
        if ($array == null) {
            $array = array();
        }
        $array[] = $path;
        #echo "adding $array<br/>";
        $open["{$area}"] = $array;
    }
    return findPath($open, $end_stations, $end_marker);
}