mta.stops.near(). You will obtain a latitude and longitude, query for nearby stops across one or more transit modes, and use the results to build features like “stops near me” or a stop picker for arrival lookups.
1
Obtain the user's coordinates
You need a latitude and longitude to query nearby stops. In a browser, use the Geolocation API to get the user’s current position.For server-side code or testing, use hardcoded coordinates:
2
Call mta.stops.near()
Pass Example response:
lat, lon, and a modes array to mta.stops.near(). The modes array accepts 'subway', 'bus', or both.3
Process and display results sorted by distance
The response is typically already sorted by
distanceMeters. Map over the stops to build a display list.4
Link a stop to arrivals
Once you have a
stopId, you can pass it directly to mta.subway.arrivals() to fetch real-time arrivals for that stop. This lets you build a “tap a stop, see arrivals” flow.Complete example
Route-aware lookups
When you already know which route the user cares about, pass aroute to mta.stops.near() so the response only includes stops served by that route. Combine it with radiusMeters and limit to scope the search precisely.
route: 'L' and modes: ['subway'] to skip every other line in the response.
Filtering by mode
Pass only the modes you need to keep the response focused. This reduces payload size and simplifies the results you render.mta.stops.near() with the active mode rather than fetching all modes and filtering client-side.
Using results with arrivals
You can chainstops.near() directly into subway.arrivals() to create a fully location-aware arrivals lookup.