Open Journey Planner SDK for iOS and other Apple platforms | Read-only mirror of https://github.com/openTdataCH/ojp-ios — SBB. Issues & pull requests at the source.
  • Swift 99.3%
  • Shell 0.7%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-03 08:54:15 +01:00
.github/workflows Update build_documentation.yml 2025-05-06 12:10:44 +02:00
SampleApp flatten PublishingActions 2026-09-15 16:29:08 +02:00
Sources/OJP writing 1.7.2 to 'Sources/OJP/Generated/Version.swift' 2026-11-02 09:30:45 +00:00
Tests/OJPTests use unkeyed container to filter out PTSituation elements that can't be decoded 2026-10-29 09:58:56 +01:00
.gitignore add .swiftpm to gitignore 2026-06-18 13:16:27 +02:00
.spi.yml Add mock to documentation (#97) 2024-12-12 12:01:38 +01:00
.swift-format Add stub LocationInformation Service and add config for swift-format 2024-03-15 16:54:39 +01:00
.swift-version Add stub LocationInformation Service and add config for swift-format 2024-03-15 16:54:39 +01:00
build-documentation.sh Initial setup for DocC 2024-03-26 22:06:16 +01:00
format-code.sh Add swiftformat for SampleApp 2024-05-03 17:05:40 +02:00
generate-version-file.sh create-version.sh will not be used any more, update README.md to match the current state of the release workflow 2025-06-05 13:55:59 +02:00
LICENSE Updates LICENSE 2024-04-09 11:39:34 +02:00
Package.resolved use unkeyed container to filter out PTSituation elements that can't be decoded 2026-10-29 09:58:56 +01:00
Package.swift SER: Add Mode Filter 2026-05-20 15:59:52 +02:00
README.md Add documentation 2026-06-25 14:53:29 +02:00

Open Journey Planner SDK for iOS and macOS

swift version shield platforms shield

Overview

This SDK is enabling Swift applications to integrate Open Journey Planner (OJP) V2 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”.

For a general introduction to OJP, consult the Cookbook on opentransportdata.swiss. Visit vdvde.github.io/OJP for the documentation of the XML Schema of OJP.

🚧 Currently this SDK is under construction. Note that APIs may still change. 🚧

Features

Available APIs

Requirements

Installation

The SDK can be integrated into your Xcode project using the Swift Package Manager. Add following dependency to your Package.swift or as a Package Dependency in Xcode:

    .package(url: "`https://github.com/openTdataCH/ojp-ios.git", from: "1.0.0"),

Usage

Initializing

import OJP

let apiConfiguration = APIConfiguration(
    apiEndPoint: URL(string: "your api endpoint")!, 
    requesterReference: "your request reference", 
    additionalHeaders: [
        "Authorization": "Bearer yourBearerToken"
    ]
)

let ojpSdk = OJP(
    loadingStrategy: .http(apiConfiguration),
    language: "de" // optional ISO language code. Defaults to the preferred localization. 
)

Basic Usage

Get a list of PlaceResult from a keyword

// get only stops
let stops = try await ojpSdk.requestPlaceResults(
    from: "Bern",
    restrictions: .init(type: [.stop])
)
        
// get stops and addresses
let addresses = try await ojpSdk.requestPlaceResults(from: "Bern", restrictions: .init(type: [.stop, .address]))

Get a List of PlaceResults around a Place using Longitude and Latitude

let nearbyStops = try await ojpSdk.requestPlaceResults(
    from: Point(long: 5.6, lat: 2.3), 
    restrictions: .init(type: [.stop])
)

Get a List of Sharing POIs within a bounding box

let modes: [OJPv2.PersonalMode] = [.bicycle, .scooter, .car]
let placeParam = OJPv2.PlaceParam(type: [], numberOfResults: 300, includePtModes: true, modeFilter: .init(personalModes: modes))

let rectangle = OJPv2.Rectangle(
    upperLeft: OJPv2.GeoPosition(
        longitude: ul.long,
        latitude: ul.lat
    ),
    lowerRight: OJPv2.GeoPosition(
        longitude: lr.long,
        latitude: lr.lat
    )
)

let sharingPOIs = try await ojp.requestPlaceResults(
    in: rectangle,
    restrictions: placeParam
    )
)

Get a List of Trips between two Places

let origin = try await ojpSdk.requestPlaceResults(
    from: "Bern", 
    restrictions: .init(type: [.stop])
).first!

let via = try await ojpSdk.requestPlaceResults(
    from: "Luzern", 
    restrictions: .init(type: [.stop])
).first!

let destination = try await ojpSdk.requestPlaceResults(
    from: "Zurich HB", 
    restrictions: .init(type: [.stop])
).first!

let tripDelivery = try await ojp.requestTrips(
    from: origin.placeRef, 
    to: destination.placeRef, 
    via: via.placeRef,
    params: .init(
        includeTrackSections: true, 
        includeIntermediateStops: true
    )
)

Get all previous and onward Stops called by a Journey

let journeyRef = timedLeg.service.journeyRef
let tripInfo = try await OJP.configured.requestTripInfo(
    journeyRef: journeyRef,
    operatingDayRef: operatingDayRef,
    params: .init(useRealTimeData: .explanatory)
    params: .init(
        useRealTimeData: .explanatory,
        includeCalls: true, 
        includeService: true, 
        includeTrackSections: false, 
        includeTrackProjection: false, 
        includePlacesContext: false, 
        includeSituationsContext:  true
    )
)

Update an existing Trip

// in order to update a trip, you need to keep around the "original" `OJPv2.TripResult` or a `OJPv2.Trip`.

// example using `OJPv2.Trip`
let tripResult = OJPv2.TripResult(trip: trip)
let tripRefineDelivery = try await OJP.configured.requestTripRefinement(tripResult: tripResult)

Get Upcoming Departures From A StopPlace

let stopEventDelivery = try await ojp.requestStopEvent(
    location: .init(
        placeRef: someStopPlace.placeRef
    ),
    params: .init(
        stopEventType: .departure
    )
)

Get Upcoming Departures Nearby

// when placeRef is a GeoPosition, use `IndividualTransportOption` to restrict the Stops returned in the request

let stopEventDelivery = try await ojp.requestStopEvent(
    location: .init(
        placeRef: someLocation.placeRef,
        individualTransportOption: [
            .init(itModeAndModeOfOperation: .init(personalMode: .foot),
                  maxDistance: 200)
        ]
    ),
    params: .init(
        numberOfResults: 20,
        stopEventType: .departure
    )
)

For a more detailed introduction head over to the Getting Started article in the documentation.

Sample App

There is an experimental Sample App to showcase and test the SDK. Currently intended to be run as a macOS app.

Documentation

Releases

See Releases for the history of all current releases.

How To Release A New Version

A new release can be prepared by creating and pushing a release/X.X.X branch. Where X.X.X is the semantic version of the release. As soon as this is pushed the prepare_release.yml workflow will:

  1. update the Version.swift file
  2. tag the release
  3. open a new PR for this release

After this PR is approved and merged the draft_release.yml workflow will draft a Github release.

Used Standards

Contributing

Contributions are welcomed. Feel free to create an issue or a feature request, or fork the project and submit a pull request.

License

MIT License, see LICENSE

Contact

Create an issue or contact opentransportdata.swiss