StopPoint search - returnLines by common name

Hi,
I have been using the API for a personal project, and was looking at creating a search page similar to the one found in the TfL Go mobile application, seen here:

I am looking specifically at the colour indicators under ‘Mile End Station’ that denote the lines available at the station.

However, I noticed that the StopPoint/Search?query={} endpoint (here) does not return any line identifier information (only line modes i.e. tube), when the StopPoint?lat=.... endpoint (to search within a radius, here) has an optional returnLines parameter, defaulting to true, that returns lines, lineGroup and lineModeGroups objects on each StopPoint, allowing an application to read line identifiers at each StopPoint.

Essentially, I was wondering whether I am missing something and it is possible to return lineModeGroups for the search by query endpoint, and if it is not possible, could a returnLines parameter or similar be added so we can retrieve this information?

I noticed that the TfL Go application was using a different api, that does return line information by name query, and it would be nice to have that parity if it is not already available.

Thank you :slight_smile:

Welcome @TomK

How about… get a list of all the lines and loop though them to get the stops on those lines?

foreach (https://api.tfl.gov.uk/line/mode/tube as <route>  ) 
foreach  { https://api.tfl.gov.uk/Line/<route>/Route/sequence/inbound  as <stations>
   process(<stations> )   
} 

B

1 Like

Or in actual code…

$modes= $this->getJson("line/mode/tube");
    $arrOut=[];
    foreach ($modes  as $mode)
    {
        $thismode=$this->getJson("Line/{$mode->id}/Route/sequence/inbound" );
        foreach($thismode->stations as $station)
        {
            if(!isset($arrOut[$station->name]))
            {
                $arrOut[$station->name]=[];
            }
            $arrOut[$station->name][]=$mode->id;
        }
    }
    ksort($arrOut);
    foreach($arrOut as $name=>$modes)
    {
        echo PHP_EOL."$name: ". join (",", $modes);
    }

output…

Acton Town Underground Station: district,piccadilly
Aldgate East Underground Station: district,hammersmith-city
Aldgate Underground Station: circle,metropolitan
Alperton Underground Station: piccadilly
Amersham: metropolitan
Angel Underground Station: northern
Archway Underground Station: northern
Arnos Grove Underground Station: piccadilly
Arsenal Underground Station: piccadilly
Baker Street Underground Station: bakerloo,circle,hammersmith-city,jubilee,metropolitan
Balham: northern
Bank: central,northern,waterloo-city
Barbican Underground Station: circle,hammersmith-city,metropolitan
Barking: district,hammersmith-city
Barkingside Underground Station: central
Barons Court Underground Station: district,piccadilly
Battersea Power Station Underground Station: northern
Bayswater Underground Station: circle,district
Becontree Underground Station: district
Belsize Park Underground Station: northern
Bermondsey Underground Station: jubilee
Bethnal Green Underground Station: central
Blackfriars: circle,district
Blackhorse Road: victoria
Bond Street: central,jubilee
Borough Underground Station: northern
Boston Manor Underground Station: piccadilly
Bounds Green Underground Station: piccadilly
Bow Road Underground Station: district,hammersmith-city
Brent Cross Underground Station: northern
Brixton: victoria
Bromley-by-Bow Underground Station: district,hammersmith-city

1 Like

Yeah, this is basically the solution I came up with. It would be nice to have parity with the API TfL are using internally though and have everything returned in one API call, rather than keep this list separately.

Thank you for providing a solution around this :slight_smile:

1 Like