- Kotlin 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| .github/workflows | ||
| app | ||
| gradle | ||
| sdk | ||
| .gitignore | ||
| gradle.properties | ||
| gradlew | ||
| gradlew.bat | ||
| LICENSE | ||
| README.md | ||
| settings.gradle.kts | ||
Open Journey Planner SDK for Android
Overview
This SDK is targeting Android applications seeking to integrate Open Journey Planner(OJP) APIs to support distributed journey planning according to the European (CEN) Technical Specification entitled “Intelligent transport systems – Public transport – Open API for distributed journey planning”
Features
Available APIs:
- Location Information Request
- Trip Request
- Trip Info Request
- Stop Event Request
- Trip Refinement Request
Requirements
Compatible with Android 8+
Integration
To integrate the SDK you have to add following dependency:
dependencies {
implementation 'io.github.opentdatach:ojp-android:1.7.3'
}
Usage
Initializing
Initialize the SDK with your custom configuration:
OjpSdk(
baseUrl = "Your Base URL",
endpoint = "Your Endpoint",
requesterReference = "Your Requester Reference",
httpHeaders = hashMapOf(
"Authorization" to "Bearer myAccessToken",
"Custom-Header" to "CustomValue"
),
defaultTimeZone = ZoneId.of("Europe/Zurich")
)
Basic Usage
Get a list of locations from a keyword
import ch.opentransportdata.ojp.OjpSdk
requestLocationsFromSearchTerm(
languageCode = LanguageCode.EN,
term = "Bern",
restrictions = LocationInformationParams(
types = listOf(PlaceTypeRestriction.STOP, PlaceTypeRestriction.ADDRESS),
numberOfResults = 10,
ptModeIncluded = true
)
)
Get a list of locations around a place with longitude and latitude
import ch.opentransportdata.ojp.OjpSdk
requestLocationsFromCoordinates(
languageCode = LanguageCode.EN,
longitude = 5.6,
latitude = 2.3,
restrictions = LocationInformationParams(
types = listOf(PlaceTypeRestriction.STOP),
numberOfResults = 10,
ptModeIncluded = true
)
)
Get a list of sharing POIs within a bounding box (rectangle)
import ch.opentransportdata.ojp.OjpSdk
requestLocationsFromRectangle(
languageCode = LanguageCode.EN,
upperLeftLongitude = 7.431,
upperLeftLatitude = 46.945,
lowerRightLongitude = 7.446,
lowerRightLatitude = 46.950,
restrictions = LocationInformationParams(
types = emptyList(),
numberOfResults = 300,
ptModeIncluded = true,
modeFilter = ModeFilter(
exclude = false,
personalModes = listOf(
PersonalMode.BICYCLE,
PersonalMode.SCOOTER,
PersonalMode.CAR
)
)
)
)
The rectangle is defined by its upper left and lower right corners (WGS84) and is typically used to load shared mobility points of interest (e.g. e-scooters, bikes, cars) for the currently visible map region. Filter the results with a ModeFilter on personalModes. Each returned PointOfInterest exposes its category via sharingCategories. A PointOfInterestFilter (with PointOfInterestCategory / OSM tags) can be passed as well.
Get a list of trips
import ch.opentransportdata.ojp.OjpSdk
requestTrips(
languageCode = LanguageCode.EN,
origin = PlaceReferenceDto(
ref = "8507000",
stationName = NameDto(text = "Bern"),
position = null
),
destination = PlaceReferenceDto(
ref = "8500010",
stationName = NameDto(text = "Basel SBB"),
position = null
),
via = null,
time = LocalDateTime.now(),
isSearchForDepartureTime = true,
params = TripParams(
numberOfResults = 10,
includeIntermediateStops = true,
includeAllRestrictedLines = true,
useRealtimeData = RealtimeData.EXPLANATORY,
optimisationMethod = OptimisationMethod.FASTEST,
walkSpeed = 100,
transferLimit = 3,
bikeTransport = false,
modeAndModeOfOperationFilter = listOf(
ModeAndModeOfOperationFilter(
ptMode = listOf(PtMode.RAIL),
exclude = false,
railSubmode = RailSubmode.HIGH_SPEED_RAIL
)
)
),
individualTransportOption = IndividualTransportOptionDto(
itModeAndModeOfOperation = ItModeAndModeOfOperationDto(
personalMode = "walk"
),
maxDistance = 500,
maxDuration = Duration.ofMinutes(10)
)
)
The individualTransportOption parameter allows you to specify individual transport options (e.g. walking, cycling) for the first/last mile of a trip. It accepts an IndividualTransportOptionDto with the following optional fields:
itModeAndModeOfOperation: The personal mode and mode of operation (e.g.walk,cycle)minDistance/maxDistance: Distance constraints in metersminDuration/maxDuration: Duration constraints asjava.time.Duration
Load previous or next trips
After a requestTrips call you can page through results without re-initialising the request:
import ch.opentransportdata.ojp.OjpSdk
// Load trips before the first result of the current list
requestPreviousTrips(numberOfResults = 5)
// Load trips after the last result of the current list
requestNextTrips(numberOfResults = 5)
Update an existing trip
Re-request a single trip with the same origin/destination to get fresh real-time data:
import ch.opentransportdata.ojp.OjpSdk
updateTripData(
languageCode = LanguageCode.EN,
origin = PlaceReferenceDto(ref = "8507000", stationName = NameDto(text = "Bern"), position = null),
destination = PlaceReferenceDto(ref = "8500010", stationName = NameDto(text = "Basel SBB"), position = null),
via = null,
params = TripParams(useRealtimeData = RealtimeData.FULL),
trip = existingTrip,
individualTransportOption = null
)
Get trip info for a specific journey
import ch.opentransportdata.ojp.OjpSdk
requestTripInfo(
languageCode = LanguageCode.EN,
journeyRef = "ojp:91-2-Y-j24-1",
operatingDayRef = "2025-02-18",
params = TripInfoParam(
useRealtimeData = RealtimeData.FULL,
includeCalls = true,
includeService = true,
includeTrackSections = true,
includeSituationsContext = true
)
)
Get stop events (departures/arrivals) for a stop
import ch.opentransportdata.ojp.OjpSdk
requestStopEvent(
languageCode = LanguageCode.EN,
location = LocationDto(
placeReference = PlaceReferenceDto(
ref = "8507000",
stationName = NameDto(text = "Bern"),
position = null
),
individualTransportOption = IndividualTransportOptionDto(maxDistance = 500)
),
params = StopEventParam(
numberOfResults = 10,
stopEventType = StopEventType.DEPARTURE,
includePreviousCalls = false,
includeOnwardCalls = true,
includeOperatingDays = true,
useRealtimeData = RealtimeData.FULL,
modeFilter = ModeFilter(
ptMode = listOf(PtMode.RAIL),
exclude = false
)
)
)
Refine a trip
import ch.opentransportdata.ojp.OjpSdk
requestTripRefinement(
languageCode = Locale.getDefault().language.toOjpLanguageCode(),
tripResult = tripResult,
params = TripRefineParam(
includeIntermediateStops = true,
includeAllRestrictedLines = true,
includeTurnDescription = true,
includeLegProjection = true,
includeTrackSections = true,
useRealtimeData = RealtimeData.FULL
)
)
Get a list of mocked trips for testing purposes
import ch.opentransportdata.ojp.OjpSdk
requestMockTrips(stream = source)
Documentation
Documentation of the Android SDK
Contributing
Contributions are welcomed. Feel free to create an issue or a feature request, or fork the project and submit a pull request.
License
Apache License, see LICENSE
Contact
Create an issue or contact opentransportdata.swiss