Mobile SDKs
Kotlin für Android/JVM und Swift für iOS. Geografische OSRMRoute-APIs mit typisierten Modellen und asynchronen Anfragen.
Mobiler Zugriff
Registrieren Sie die App, richten Sie die Plattformprüfung ein und aktivieren Sie den Zugriff.
Apps teilen das Kontingent ihres API-Schlüssels. Limits zählen dessen gesamten Datenverkehr; eine Registrierung fügt keine Credits hinzu.
App registrieren →- Plattform und App-Identität registrieren
- Anbieter verbinden und echtes Gerät prüfen
- SDK einbinden, Zugriff aktivieren und Anfrage senden
Kotlin und Swift SDK 0.2.0 enthalten Mobile Access. Installieren Sie das stabile Paket, konfigurieren Sie die Plattformprüfung und verwenden Sie Ihre öffentliche App-ID.
Android · Play Integrity
Registrieren Sie Ihre App bei Google Play und verbinden Sie das Cloud-Projekt mit Play Integrity. Senden Sie dem Support die öffentliche OSRMRoute App ID, den Paketnamen und die Cloud-Projektnummer. Wir organisieren die sichere Übertragung der Zugangsdaten separat und bestätigen die Verbindung. Installieren Sie danach über einen Play-Testkanal, aktivieren Sie den Zugriff und prüfen Sie ein echtes Gerät. Keine privaten Schlüssel an Tickets anhängen.
SHA-256 des App-Signaturzertifikats
Google Play Console → App integrity → App signing key certificate → SHA-256. Fingerabdruck mit Doppelpunkten einfügen; Umwandlung automatisch.
implementation("com.google.android.play:integrity:1.6.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.10.1")import android.content.Context
import android.util.Base64
import com.google.android.play.core.integrity.IntegrityManagerFactory
import com.google.android.play.core.integrity.StandardIntegrityManager
import com.osrmroute.MobileAccess
import com.osrmroute.OSRMRoute
import kotlinx.coroutines.tasks.await
import java.util.UUID
// Call once; reuse the returned pair and close both when no longer needed.
suspend fun makeMapClient(context: Context, cloudProjectNumber: Long): Pair<MobileAccess, OSRMRoute> {
val appId = "YOUR_PUBLIC_APP_ID"
val prefs = context.getSharedPreferences("osrmroute.$appId", Context.MODE_PRIVATE)
val keyId = prefs.getString("installation", null) ?: UUID.randomUUID().toString().also {
prefs.edit().putString("installation", it).apply()
}
val provider = IntegrityManagerFactory.createStandard(context.applicationContext)
.prepareIntegrityToken(StandardIntegrityManager.PrepareIntegrityTokenRequest.builder()
.setCloudProjectNumber(cloudProjectNumber).build()).await()
val access = MobileAccess(appId, keyId) { payload ->
val hash = Base64.encodeToString(MobileAccess.requestHash(payload),
Base64.URL_SAFE or Base64.NO_WRAP or Base64.NO_PADDING)
provider.request(StandardIntegrityManager.StandardIntegrityTokenRequest.builder()
.setRequestHash(hash).build()).await().token()
}
return access to OSRMRoute(baseUrl = "https://osrmroute.com", tokenProvider = { access.token() })
}
// cloudProjectNumber: your Google Cloud project linked to Play Integrity.
// After enabling the app and allowing the geocode scope:
// val (access, client) = makeMapClient(context, yourCloudProjectNumber)
// val result = client.geocode("Berlin", 1)iOS · App Attest
10-stelliges App ID prefix aus Apple Developer kopieren. Production App Attest in der signierten App aktivieren.
import Foundation
import OSRMRoute
// Call once during application setup; retain and reuse the returned client.
@MainActor
func makeMapClient() async throws -> OSRMRouteClient {
let appID = "YOUR_PUBLIC_APP_ID"
let storageKey = "osrmroute.attest.\(appID)"
let keyID: String
if let saved = UserDefaults.standard.string(forKey: storageKey) {
keyID = saved
} else {
keyID = try await AppleMobileProof.generateKey()
UserDefaults.standard.set(keyID, forKey: storageKey)
}
let access = try MobileAccess(appID: appID, keyID: keyID) { payload, enrolled in
try await AppleMobileProof.proof(keyID: keyID, payload: payload, enrolled: enrolled)
}
return try OSRMRouteClient(baseURL: URL(string: "https://osrmroute.com")!) {
try await access.token()
}
}
// After enabling the app and allowing the geocode scope:
// let client = try await makeMapClient()
// let result = try await client.geocode("Berlin", limit: 1)Alternative: eigenes Backend verwenden
Speichern Sie den OSRMRoute-Schlüssel auf Ihrem Server. Die App sendet ihre kurzlebige Sitzung an Ihren authentifizierten Proxy. Dieser prüft erlaubte Endpunkte, Benutzerzugriff und Limits und ergänzt den OSRMRoute-Schlüssel serverseitig. Leiten Sie den App-Token nicht an OSRMRoute weiter.
Herunterladen und installieren
Installieren Sie Kotlin 0.2.0 über Maven Central und Swift 0.2.0 über die öffentliche GitHub-URL in Xcode oder Swift Package Manager. Der Quellcode ist auch als ZIP verfügbar.
dependencyResolutionManagement {
repositories { mavenCentral() }
}dependencies {
implementation("com.osrmroute:osrmroute-kotlin:0.2.0")
}
// AndroidManifest.xml:
// <uses-permission android:name="android.permission.INTERNET" />.package(url: "https://github.com/Mammadoff/osrmroute-swift.git", from: "0.2.0")
// Xcode: File > Add Package Dependencies > enter the GitHub URL.
// Add the OSRMRoute library to your application target.Kotlin · Android / JVM
GitHub · Kotlinimport 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
GitHub · Swiftimport 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].distanceUnterstützte Methoden
Typisierte Antworten: route, matrix, geocode, reverse und autocomplete. Places liefert JSON. getJson/getJSON und postJson/postJSON unterstützen weitere geografische Endpunkte. Tariflimits und Abdeckung gelten weiterhin.
Anfragen und Fehler
Standardmäßig keine Wiederholungen. Optional bis zu zwei Wiederholungen für GET mit 429, 502, 503 oder 504. Retry-After über 30 Sekunden oder als Datum wird nicht wiederholt. Netzwerkfehler und POST werden nie automatisch wiederholt.
// 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.Nur API-Integration
Keine Kartendarstellung, Offlinekarten oder Navigation. Kotlin: Android API 21+ und JVM 17; Swift: iOS 15+ und macOS 12+. Pakettests ersetzen keine Gerätetests.
Dokumentation →