Nearby Stops

Demonstration

Stops near
2 MetroTech Center, Brooklyn, NY 11201

  • A C E B D F M G L J Z N Q R W 1 2 3 4 5 6 6 Express 7 7 Express S
Code

Nearby Stops will parse a list of MTA subway transit data from the NYC Open Data Portal and use a single latitude and longitude to locate the nearest stop. It will not fetch the data directly but will retrieve it from a local endpoint.

Global Script

Nearby Stops requires JavaScript for fetching data and rendering subway stop templates. To initialize the Nearby Stops instance from the global script use the following code:

<script src="https://cdn.jsdelivr.net/gh/nycopportunity/standard@v0.0.20/dist/js/default.js"></script>

<script>
  var Standard = new Default();

  Standard.nearbyStops();
</script>
Module

For module imports, import the Nearby Stops module from the source.

import NearbyStops from '@nycopportunity/standard/src/components/nearby-stops/nearby-stops';

new NearbyStops();

The class will select any DOM element with the data-js="nearby-stops" attribute and look up the closest stops to the location embedded in the data-nearby-stops-location attribute. The location attribute accepts an array of latitude and longitude.

Use the data-nearby-stops-endpoint attribute to set the endpoint for the Subway stops data. The amount of stops defaults to 3 but can be overwritten using the data-nearby-stops-amount attribute, which accepts a number of stops to display.