API for getting the nearest train stations?

I want to use a coordinate to return all kinds of data which includes nearest train stations. I have tried using the API (https://api.tfl.gov.uk/Place/Meta/placeTypes) but I don’t see any type for the train station. Do we have an API for getting the nearest train stations from a coordinate?

There is indeed an API for getting the train stations around a geographic coordinate, but it requires that you set a radius (or use the default of 200m).

Stations do not appear in /Place/Meta/PlaceTypes because they are considered StopPoints, not Places, as far as I’m aware. You can get a list of different StopTypes at https://api.tfl.gov.uk/StopPoint/Meta/StopTypes.

2 Likes

Or, just download the whole list and do it yourself using radial distance calculations. There aren’t that may of them and so it’s a quicker if you want to do it a lot.

Also… some stations are really spread out (St Pancras) and others are almost a simple dot (Camden Road) so what’s the “nearest” might not actually accessible from a lat,long a person might be at.

And you’re looking for NaptanMetroStation and NaptanRailStation because it’s “National Public Transport Access Nodes”

1 Like

I don’t think that’s a quicker way to do it. Just provide a pretty large radius and then the closest stop will always be the first in the list. Downloading a list of all the stop points and then looping through each one with a coordinate is a lot more work than 1 API call.

The walking distance/straight line distance issue is still there either way though obviously

Local CPU cycles are always going to be faster by a huge factor than remote ones. :slight_smile: