Getting started¶
Maas components for iOS¶
Work in progress, not ready for use in production.
Frictionless access to mobility-as-a-service (MaaS) data and services. Ready-built UI components to get you started quickly out of the box, built with SwiftUI.
Usage¶
Search for locations.
let locationsApi = LocationsApi(baseUrl: "<#APIBaseURL#>", apiKey: "<#APIKey#>", regionId = "<#RegionID#>")
let result = locationsApi.search(query) { result in
switch result {
case .success(let result): print("Found \(result.value.size) locations.")
case .failure(let error): print("Error: \(error.localizedDescription)")
}
}
Geocode and reverse geocode locations.
let coordinate = LatLng(lat: 54.685563, lng: 25.287704)
let end = locationsApi.resolveAddress(coordinate).flatMap { address in
Location(coordinate, address: address)
}
Search for routes.
let routesApi = RoutesApi(baseUrl: "<#APIBaseURL#>", apiKey: "<#APIKey#>")
routesApi.search(start, end) { result in
switch result {
case .success(let results): print("Found \(results.routes.size) routes.")
case .failure(let error): print("Error: \(error.localizedDescription)")
}
}
Display those routes with SwiftUI.
var body: some View {
RoutesResultView(results)
}
MaaS Components for Android¶
Work in progress, not ready for use in production.
Frictionless access to mobility-as-a-service (MaaS) data and services. Ready-built UI components to get you started quickly out of the box, built with Jetpack Compose.
Usage¶
Search for locations.
dependencies {
implementation 'com.trafi.maas:locations-android:0.1.0-dev02'
}
val locationsApi = LocationsApi(baseUrl = "$API_BASE_URL", apiKey = "$API_KEY", regionId = "$REGION_ID")
lifecycleScope.launch {
val result = locationsApi.search(query)
when (result) {
is ApiResult.Success -> println("Found ${result.value.size} locations.")
is ApiResult.Failure -> throw result.exception
}
}
Geocode and reverse geocode locations.
lifecycleScope.launch {
val start = locationsApi.resolveLocation(location)
val coordinate = LatLng(54.685563, 25.287704)
val end = (locationsApi.resolveAddress(coordinate) as? ApiResult.Success)?.value?.let { address ->
Location(coordinate, address = address)
}
}
Search for routes.
dependencies {
implementation 'com.trafi.maas:routes-android:0.1.0-dev02'
}
val routesApi = RoutesApi(baseUrl = "$API_BASE_URL", apiKey = "$API_KEY")
lifecycleScope.launch {
val result = routesApi.search(start, end)
when (result) {
is ApiResult.Success -> println("Found ${result.value.routes.size} routes.")
is ApiResult.Failure -> throw result.exception
}
}
Display those routes with Jetpack Compose.
dependencies {
implementation 'com.trafi.maas:routes-ui-android:0.1.0-dev02'
}
setContent {
RoutesResult(result)
}
Or try out the included sample.