Skip to main content
GuidesAPI ReferenceExamplesFAQ

Public Transit stops

Estimated reading time: 5 minutes

This API provides detailed access to public transport data including agencies, routes, stops, and trips. It is designed to integrate with interactive map-based applications using the Magic Lane SDK and allows developers to dynamically fetch and explore real-time public transportation information from selected positions on the map.

Key Features

  • Query public transport overlays by screen position.
  • Retrieve structured information about transport agencies, stops, routes, and trips.
  • Support for real-time data including delays and cancellations.
  • Metadata about accessibility, bike allowances, and platform details.
  • Utilities for filtering trips by route type, route short name, or agency.

How It Works

  • Set a position on the map using setCursorScreenPosition.
  • Query for public transport overlays with cursorSelectionOverlayItemsByType or for generic overlays with cursorSelectionOverlayItems.
  • Retrieve stop information using getPTStopInfo() on each overlay item.
  • Use the returned PTStopInfo object to explore agencies, stops, and trips.
  • This API is part of a modular system intended to support rich and interactive transit applications.

An example of using this feature is the following:

void _onMapCreated(GemMapController controller) async {
// Save controller for further usage.
_mapController = controller;

_mapController.registerLongPressCallback((pos) async {
// set cursor position on the screen
await _mapController.setCursorScreenPosition(pos);

// get the public transit overlay items at that position
final items = _mapController
.cursorSelectionOverlayItemsByType(CommonOverlayId.publicTransport);

// for each overlay item at that position
for (final OverlayItem item in items) {
// get the stop information
final ptStopInfo = await item.getPTStopInfo();
if (ptStopInfo != null) {
// information about agencies
final agencies = ptStopInfo.agencies;

// information about stops and generic routes
// (routes that don't have `heading` set)
final stops = ptStopInfo.stops;

// information about trips (together with
// route, agency, stop times, real time info, etc.)
final trips = ptStopInfo.trips;

// How to use stops
for (final stop in stops) {
print('Stop id: ${stop.stopId}');
print('Stop name: ${stop.stopName}');

print('Routes:');
for (final route in stop.routes) {
print(' Route id: ${route.routeId}');
print(' Route short name: ${route.routeShortName}');
print(' Route long name: ${route.routeLongName}');
}
}
}
}
});
}

You can filter the trips by:

  • route short name (tripsByRouteShortName)
  • route type(tripsByRouteType)
  • agency (tripsByAgency)

These can be accomplished by using the following methods of the PTStopInfo class:

List<PTTrip> tripsByRouteShortName(String name)
List<PTTrip> tripsByRouteType(PTRouteType type)
List<PTTrip> tripsByAgency(PTAgency agency)

An example illustrating this is the following:

final trips = ptStopInfo.tripsByRouteType(PTRouteType.bus);

PTAgency

Represents a public transport agency.

PropertyTypeDescription
idintAgency ID
nameStringAgency name
urlString?Optional website URL

PTRouteType

Enum representing route types.

enum PTRouteType {
bus,
underground,
railway,
tram,
waterTransport,
misc
}

PTRoute

Represents a public transport route.

PropertyTypeDescription
routeIdintRoute ID
routeShortNameString?Short name
routeLongNameString?Long name
routeTypePTRouteTypeType of route
routeColorColor?Color in hex
routeTextColorColor?Text color in hex
headingString?Optional heading

PTStop

Represents a public transport stop.

PropertyTypeDescription
stopIdintStop ID
stopNameStringStop name
isStationbool?Is station or not
routesList<PTRoute>Associated routes

PTStopTime

Details a stop time in a trip.

PropertyTypeDescription
stopNameStringStop name
coordinatesCoordinatesLat/Lon
hasRealtimeboolReal-time available
delayintDelay in seconds
departureTimeDateTime?Optional departure time
isBeforeboolIs before current time
isWheelchairFriendlyboolWheelchair accessible

PTTrip

Describes a public transport trip.

PropertyTypeDescription
routePTRouteAssociated route
agencyPTAgencyAssociated agency
tripIndexintTrip index
tripDateDateTime?Date
departureTimeDateTime?Departure
hasRealtimeboolRealtime info
isCancelledbool?Cancelled
delayMinutesint?Delay
stopTimesList<PTStopTime>Times at stops
stopIndexintStop index
stopPlatformCodeStringPlatform
isWheelchairAccessibleboolWheelchair access
isBikeAllowedboolBike allowed

PTStopInfo

Aggregates stop-related data.

PropertyTypeDescription
agenciesList<PTAgency>Available agencies
stopsList<PTStop>Nearby stops
tripsList<PTTrip>Available trips