Home/Guides/Developers
Developers

How to search for nearby transit stops with an API?

Learn how to search for nearby transit stops with the ROOTE API: coordinates, radius, JavaScript example, reading results and error handling.

By ROOTE·5 min read
How to search for nearby transit stops with an API?
Every journey starts nearby.

The essentials at a glance

To search for stops around a point, send its latitude, longitude and a radius to a proximity API. Then check the response status, returned entities and coverage information before displaying a list or a map.

To search for stops around a point, send its latitude, longitude and a radius to a proximity API. Then check the response status, returned entities and coverage information before displaying a list or a map.

In the ROOTE contract roote-1.0.0, the GET /v1/transit/nearby route discovers nearby transport places. It does not retrieve departures or real-time alerts. Searching for a place and searching for its next departure are two distinct operations.

Define the parameters

The request uses lat for latitude and lng for longitude. The alias lon is also described in the contract. The radius parameter expresses the radius in meters; limit bounds the number of requested results. The modes filter can specify transport modes.

Parameter Example Meaning
lat 44.8378 Search point latitude
lng -0.5792 Search point longitude
radius 600 Requested radius in meters
limit 10 Requested result limit
modes bus,tram Searched modes

These coordinates are an example for a search in Bordeaux; they do not guarantee a specific stop. See the ROOTE OpenAPI contract for current bounds, fields and conditions.

Try it now

Find transport stops nearby.

Explore stops listed around a city or your location. Check the details for transport modes and available information.

Send a first request from the server side

Here is a JavaScript example for a Node.js environment with fetch. The token, if your access uses one, stays in a server-side environment variable. The example does not require placing a secret in the browser.

async function rechercherArrets(token = process.env.ROOTE_API_TOKEN) {
  const url = new URL('https://api.roote.ai/v1/transit/nearby');
  url.search = new URLSearchParams({
    lat: '44.8378',
    lng: '-0.5792',
    radius: '600',
    limit: '10',
    modes: 'bus,tram'
  }).toString();

  const headers = { Accept: 'application/json' };
  if (token) headers.Authorization = `Bearer ${token}`;

  const response = await fetch(url, {
    headers,
    signal: AbortSignal.timeout(10000)
  });
  if (!response.ok) {
    throw new Error(`Erreur HTTP ${response.status}`);
  }

  const data = await response.json();
  if (data.contract_version !== 'roote-1.0.0') {
    throw new Error('Version du contrat non reconnue');
  }
  if (!['success', 'empty', 'partial'].includes(data.status)) {
    throw new Error('Recherche indisponible');
  }
  if (!Array.isArray(data.stations)) {
    throw new Error('Réponse sans collection stations valide');
  }

  return {
    status: data.status,
    stations: data.stations,
    lines: data.lines,
    operators: data.operators,
    coverage: data.coverage,
    warnings: data.warnings,
    attributions: data.attributions,
    meta: data.meta
  };
}

The consulted contract allows anonymous or token access, depending on applicable policies. Verify your rights and access limits. A successful HTTP response does not exempt you from validating its content; in production, also validate objects against the schema.

Read entities and their relations

The stations collection contains the returned places. For each, check id, name, entity_kind, location and distance_meters. The line_ids and operator_ids references allow associating the lines and operators collections when they are provided.

Display a geographic distance as such. Do not convert it to walking time without routing calculation. The guide finding a nearby stop explains why access conditions can change actual travel.

Also handle explicitly unknown information. In the contract, accessibility.wheelchair can be unknown: this value is neither yes nor no. A declared departure capacity is not a list of departures.

Show a list or a map

Use the identifier to stabilize interface elements, the name for their label and location for their position. Associate lines using references, rather than by matching their names.

If you display line colors or labels coming from the data, treat them as external inputs to validate. For names, use text rather than injected HTML.

Keep source attributions and display those the contract indicates as required.

Handle empty result, partial response and error

An empty result describes a search with no results returned within the known perimeter. It does not prove the physical absence of transport. A partial response may contain useful places while indicating limits: present the results and the appropriate warning.

Read coverage, warnings and applied limits in meta. A truncated list does not describe exhaustive coverage. In case of network or HTTP error, show an unavailability state, without replacing the result with "no stops".

For a 429 code, consult retry guidance and any service headers. Avoid retry loops.

Distinguish stations, areas and platforms

The entity_kind field distinguishes several place levels. Two nearby results may correspond to distinct platforms; two similar names may come from different sources.

Do not automatically merge places based on proximity alone. Use relations and identities documented by the service. Our guide GTFS, GTFS-RT and GBFS explains the data context.

Prepare the production integration

Trigger searches when position or filters change meaningfully. Group identical calls, set a timeout and adapt caching to the data type and service conditions.

A list of places and a real-time availability feed do not have the same freshness requirements. Test the flow with complete, empty, partial and error responses before presenting the search to users.

For developersROOTE Mobility API

Mobility around a location.
Directly in your application.

  • Search
    around a location
  • Access
    mobility data
  • Integrate into
    your application

From the map to the data: find nearby mobility options and services with the ROOTE API.

Frequently asked questions

Does Nearby provide upcoming departures?

Not in the contract shown here. This route discovers transport places; departures require a separate capability.

Can I show an empty list after an error?

Show an unavailability state. An error does not demonstrate the absence of stops.

Can I put the API token in the browser?

A secret must remain server-side. Use the access model provided for your application and account.

Why not explore nearby?

Explore your neighbourhood with ROOTE and find the information available to prepare your journey.

Explore the ROOTE map ↗