Skip to main content

Public Transit stops

|

This API provides detailed access to public transport data including agencies, routes, stops, and trips. It integrates 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.

Tip

The structure of the public transport data is modeled after the General Transit Feed Specification (GTFS) and offers access to a subset of the fields and entities defined in GTFS.

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
  • Filter trips by route type, route short name, or agency

How It Works

Set a cursor position on the map and query for public transport overlay items at that location. Each overlay item provides access to detailed stop information including agencies, routes, and trip schedules.

mapView.onLongDown = { screenPosition ->
// Set cursor position on the screen
mapView.cursorScreenPosition = screenPosition

// Get the public transit overlay items at that position
val overlayItems = mapView.cursorSelectionOverlayItems

overlayItems?.forEach { overlayItem ->
// Check if this is a public transit overlay
if (overlayItem.overlayUid == ECommonOverlayId.PublicTransport.value) {
// Get the preview extended data
val previewDataList = GemList<Parameter>()

overlayItem.getPreviewExtendedData(
previewDataList,
ProgressListener.create(
onCompleted = { errorCode ->
if (errorCode == GemError.NoError) {
// Process the public transit data
previewDataList.forEach { parameter ->
Log.d("PT", "${parameter.key}: ${parameter.valueString}")
}
}
}
)
)
}
}
}
Tip

You can also obtain public transit overlay items by performing an overlay search using ECommonOverlayId.PublicTransport. Once you retrieve the corresponding OverlayItems, use their getPreviewExtendedData method to access the stop information.

See the Search on overlays guide for more details.

danger

All returned times are local times represented as Unix timestamps in seconds.

Use the TimeService to convert them to other time zones.

danger

There are two types of public transit stops on the map:

  • Stops which are of type OverlayItem and can be selected via the cursorSelectionOverlayItems property. These stops provide extensive details accessible through getPreviewExtendedData. They are displayed with a blue icon when using the default style.
  • Stops which are of type Landmark and can be selected via the cursorSelectionLandmarks property. These stops do not provide extensive details. They are displayed with a gray icon when using the default style.

Working with Public Transit Data

The public transit data is provided as a list of Parameter objects. Each parameter contains a key-value pair representing different aspects of the transit stop information.

Accessing Stop Information

val previewDataList = GemList<Parameter>()

overlayItem.getPreviewExtendedData(
previewDataList,
ProgressListener.create(
onCompleted = { errorCode ->
if (errorCode == GemError.NoError) {
previewDataList.forEach { parameter ->
when (parameter.key) {
EPublicTransitOverlayParamsKeys.StopId.value -> {
val stopId = parameter.valueLong
Log.d("PT", "Stop ID: $stopId")
}
EPublicTransitOverlayParamsKeys.StopName.value -> {
val stopName = parameter.valueString
Log.d("PT", "Stop Name: $stopName")
}
EPublicTransitOverlayParamsKeys.AgencyId.value -> {
val agencyId = parameter.valueLong
Log.d("PT", "Agency ID: $agencyId")
}
EPublicTransitOverlayParamsKeys.AgencyName.value -> {
val agencyName = parameter.valueString
Log.d("PT", "Agency Name: $agencyName")
}
}
}
}
}
)
)

Parameter Keys

The following parameter keys are available for public transit data:

Agency Information

Parameter KeyTypeDescription
EPublicTransitOverlayParamsKeys.AgencyIdLongAgency ID
EPublicTransitOverlayParamsKeys.AgencyNameStringFull name of the transit agency
EPublicTransitOverlayParamsKeys.AgencyURLStringURL of the transit agency

Route Information

Parameter KeyTypeDescription
EPublicTransitOverlayParamsKeys.RouteIdLongRoute ID
EPublicTransitOverlayParamsKeys.RouteShortNameStringShort name of a route (e.g., "32", "100X")
EPublicTransitOverlayParamsKeys.RouteLongNameStringFull name of a route with destination or stop
EPublicTransitOverlayParamsKeys.RouteTypeIntType of route (see ERouteType)
EPublicTransitOverlayParamsKeys.RouteColorStringRoute color designation
EPublicTransitOverlayParamsKeys.RouteTextColorStringText color for route
EPublicTransitOverlayParamsKeys.RouteHeadingStringOptional heading information

Stop Information

Parameter KeyTypeDescription
EPublicTransitOverlayParamsKeys.StopIdLongStop/platform, station, entrance/exit identifier
EPublicTransitOverlayParamsKeys.StopNameStringName of the location
EPublicTransitOverlayParamsKeys.StopTimeLatitudeParameterListLatitude coordinate of the stop
EPublicTransitOverlayParamsKeys.StopTimeLongitudeDoubleLongitude coordinate of the stop
EPublicTransitOverlayParamsKeys.IsStationBooleanWhether this location is a station
EPublicTransitOverlayParamsKeys.RoutesParameterListAssociated routes for the stop

Trip Information

Parameter KeyTypeDescription
EPublicTransitOverlayParamsKeys.TripIndexLongTrip index
EPublicTransitOverlayParamsKeys.TripDateLongDate of the trip (Unix timestamp in seconds)
EPublicTransitOverlayParamsKeys.TripDepartureTimeLongDeparture time from first stop (Unix timestamp in seconds)
EPublicTransitOverlayParamsKeys.TripHasRealtimeBooleanWhether real-time data is available
EPublicTransitOverlayParamsKeys.TripIsCancelledBooleanWhether the trip is cancelled
EPublicTransitOverlayParamsKeys.TripDelayMinutesIntDelay in minutes
EPublicTransitOverlayParamsKeys.TripStopIndexIntStop index
EPublicTransitOverlayParamsKeys.TripStopPlatformCodeStringPlatform code
EPublicTransitOverlayParamsKeys.TripWheelchairAccessibleIntWheelchair accessibility (see EWheelchairAccessible)
EPublicTransitOverlayParamsKeys.TripBikesAllowedIntBikes allowed status (see EBikesAllowed)
EPublicTransitOverlayParamsKeys.TripAgencyIdLongAgency ID for this trip
EPublicTransitOverlayParamsKeys.TripStopTimesParameterListList of stop times for this trip
EPublicTransitOverlayParamsKeys.TripHasShapeBooleanWhether trip has shape data

Stop Time Information

Parameter KeyTypeDescription
EPublicTransitOverlayParamsKeys.StopTimeNameStringName of the serviced stop
EPublicTransitOverlayParamsKeys.StopTimeLatitudeParameterListLatitude of the stop
EPublicTransitOverlayParamsKeys.StopTimeLongitudeDoubleLongitude of the stop
EPublicTransitOverlayParamsKeys.StopTimeHasRealTimeBooleanWhether data is provided in real-time
EPublicTransitOverlayParamsKeys.StopTimeDelayIntDelay in seconds
EPublicTransitOverlayParamsKeys.StopTimeDepartureTimeLongDeparture time (Unix timestamp in seconds)
EPublicTransitOverlayParamsKeys.StopTimeIsBeforeBooleanWhether stop time is before current time
EPublicTransitOverlayParamsKeys.StopTimeDetailsIntStop details including wheelchair accessibility

Route Types

The ERouteType enum represents different types of public transport.

Enum ValueDescription
BusBus, Trolleybus. Used for short and long-distance bus routes.
UndergroundSubway, Metro. Any underground rail system within a metropolitan area.
RailwayRail. Used for intercity or long-distance travel.
TramTram, Streetcar, Light rail. Any light rail or street level system within a metropolitan area.
WaterTransportWater transport. Used for ferries and other water-based transit.
MiscMiscellaneous. Includes other types of public transport not covered by the other categories.

Filtering by Route Type

previewDataList.forEach { parameter ->
if (parameter.key == EPublicTransitOverlayParamsKeys.RouteType.value) {
when (parameter.valueLong.toInt()) {
ERouteType.Bus.value -> Log.d("PT", "Bus route")
ERouteType.Underground.value -> Log.d("PT", "Underground route")
ERouteType.Railway.value -> Log.d("PT", "Railway route")
ERouteType.Tram.value -> Log.d("PT", "Tram route")
ERouteType.WaterTransport.value -> Log.d("PT", "Water transport route")
ERouteType.Misc.value -> Log.d("PT", "Miscellaneous route")
}
}
}

Wheelchair Accessibility

The EWheelchairAccessible enum indicates wheelchair accessibility information.

Enum ValueDescription
NoInfoNo accessibility information for the trip
YesVehicle can accommodate at least one rider in a wheelchair
NoNo riders in wheelchairs can be accommodated on this trip

Bikes Allowed

The EBikesAllowed enum indicates whether bikes are allowed.

Enum ValueDescription
NoInfoNo bike information for the trip
YesVehicle can accommodate at least one bicycle
NoNo bicycles are allowed on this trip