Mobil SDK’lar
Android/JVM için Kotlin, iOS için Swift. Tipli modeller ve asenkron isteklerle OSRMRoute coğrafi API’lerine bağlanın.
Mobil erişim
Uygulamayı kaydedin, platform doğrulamasını yapılandırın ve erişimi etkinleştirin.
Uygulamalar bağlı API anahtarının kotasını paylaşır. Sınırlar bu anahtarın tüm trafiğini kapsar; uygulama kaydı kredi eklemez.
Uygulama kaydet →- Platform ve uygulama kimliğini kaydedin
- Sağlayıcıyı bağlayıp gerçek cihazı doğrulayın
- SDK ekleyin, erişimi açıp istek gönderin
Kotlin ve Swift SDK 0.2.0 Mobile Access içerir. Kararlı paketi kurun, platform doğrulamasını yapılandırın ve genel uygulama kimliğinizi kullanın.
Android · Play Integrity
Uygulamanızı Google Play’de kaydedip Cloud projesini Play Integrity’ye bağlayın. Açık OSRMRoute App ID, paket adı ve Cloud proje numarasıyla desteğe başvurun. Özel kimlik bilgisinin aktarımını ayrıca düzenleyip bağlantıyı onaylayacağız. Ardından Play test kanalından kurun, erişimi açın ve gerçek cihazı doğrulayın. Tickete özel anahtar eklemeyin.
Uygulama imzalama sertifikası SHA-256
Google Play Console → App integrity → App signing key certificate → SHA-256. İki noktalı parmak izini yapıştırın; dönüşüm otomatiktir.
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
Apple Developer’dan 10 karakterlik App ID prefix kopyalayın. İmzalı uygulamada production App Attest etkin olmalıdır.
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)Alternatif: kendi backend’inizi kullanın
OSRMRoute API anahtarını sunucunuzda tutun. Uygulama kısa ömürlü oturumunu kendi kimlik doğrulamalı proxy hizmetinize gönderir. Proxy izin verilen uç noktaları, kullanıcı erişimini ve kullanım sınırlarını denetlemeli, OSRMRoute anahtarını sunucuda eklemelidir. Uygulama tokenini OSRMRoute’a iletmeyin.
İndirin ve kurun
Kotlin 0.2.0 paketini Maven Central üzerinden, Swift 0.2.0 paketini herkese açık GitHub URL’siyle Xcode veya Swift Package Manager üzerinden kurun. Kaynak ZIP dosyaları da indirilebilir.
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].distanceDesteklenen metotlar
Tipli yanıtlar: route, matrix, geocode, reverse ve autocomplete. Places JSON döndürür. getJson/getJSON ve postJson/postJSON diğer coğrafi uç noktaları destekler. Sunucu plan sınırları ve kapsamı geçerlidir.
İstekler ve hatalar
Varsayılan tekrar sayısı sıfırdır. İsteğe bağlı tekrar yalnızca 429, 502, 503 veya 504 GET yanıtlarında en fazla iki kez yapılır. Retry-After 30 saniyeyi aşıyorsa veya tarih biçimindeyse tekrarlanmaz. Ağ hataları ve POST istekleri otomatik tekrarlanmaz.
// 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.Yalnızca API entegrasyonu
Paketler harita çizmez, çevrimdışı harita veya adım adım navigasyon sunmaz. Kotlin Android API 21+ ve JVM 17; Swift iOS 15+ ve macOS 12+ içindir. Paket testleri gerçek cihaz testlerinin yerini tutmaz.
Dokümantasyon →