osrmroute
Documentation

Mobile SDKs

Kotlin for Android/JVM and Swift for iOS. Call OSRMRoute geographic APIs with typed models and asynchronous requests.

Connect through your backend

Keep your OSRMRoute API key on your server. The app supplies its short-lived application session to your own authenticated proxy. The proxy must allowlist endpoints, enforce user access and usage limits, and inject the OSRMRoute key server-side. It must not forward the application token to OSRMRoute.

Download and install

Version 0.1.0 is available as a source package. Kotlin is not published to Maven Central. Extract the Kotlin package and include it as a Gradle module; add the Swift folder as a local package in Xcode.

settings.gradle.kts
// Extract the Kotlin archive into your project folder.
include(":osrmroute-kotlin")
project(":osrmroute-kotlin").projectDir = file("osrmroute-kotlin-0.1.0")
app/build.gradle.kts
dependencies {
    implementation(project(":osrmroute-kotlin"))
}
// AndroidManifest.xml:
// <uses-permission android:name="android.permission.INTERNET" />
Xcode · Swift Package Manager
Xcode → File → Add Package Dependencies → Add Local
// Select the extracted osrmroute-swift-0.1.0 folder.
// Add the OSRMRoute library to your application target.

Kotlin · Android / JVM

Kotlin
import com.osrmroute.OSRMRoute
import com.osrmroute.Coordinate

// Call from a coroutine. Use your app session, not an embedded OSRMRoute key.
val client = OSRMRoute(
    baseUrl = "https://your-backend.example/location",
    tokenProvider = { applicationSessionToken }
)
val result = client.route(listOf(
    Coordinate(latitude = 52.52, longitude = 13.405),
    Coordinate(latitude = 52.50, longitude = 13.39)
))
val metres = result.routes.first().distance
// Close the shared client when its owner is disposed.
client.close()

Swift · iOS

Swift
import Foundation
import OSRMRoute

// Call from an async function. Use your own authenticated backend.
let client = try OSRMRouteClient(
    baseURL: URL(string: "https://your-backend.example/location")!,
    tokenProvider: { applicationSessionToken }
)
let result = try await client.route([
    Coordinate(latitude: 48.8566, longitude: 2.3522),
    Coordinate(latitude: 48.8606, longitude: 2.3376)
])
let metres = result.routes[0].distance

Supported methods

Typed responses: route, matrix, geocode, reverse and autocomplete. Places returns JSON. getJson/getJSON and postJson/postJSON support additional geographic API endpoints. Server plan limits and coverage still apply.

Requests and errors

Retries default to zero. Opt-in retries apply only to GET responses with status 429, 502, 503 or 504, at most twice. Retry-After delays over 30 seconds or date-form headers are not replayed. Network failures and POST requests are never retried automatically.

Kotlin / Swift
// Kotlin: OSRMRouteException.status and .code
// Swift: SDKError.http(status:), .transport, .invalidResponse, .invalidInput
// Cancellation propagates to the caller.
// Default timeout: 30 seconds. Configurable maximum: 120 seconds.
// Coordinates: latitude, longitude. Distances: metres. Durations: seconds.
// Matrix null cells mean unreachable, not zero.

API integration only

These packages do not render maps, provide offline maps or implement turn-by-turn navigation. Kotlin targets Android API 21+ and JVM 17; Swift targets iOS 15+ and macOS 12+. Package tests do not replace real-device acceptance.

Documentation →
Support team

OSRMRoute Support

Talk directly to our team

HERE TO HELP

How can we help?

Ask about integration, billing or your account. Our replies appear in this conversation.

Your chats

Your chats will appear here.