Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Available APIs:
- [Trip Request](https://opentransportdata.swiss/en/cookbook/ojptriprequest/)
- [Trip Info Request](https://opentransportdata.swiss/de/cookbook/open-journey-planner-ojp/ojptripinforequest/)
- [Stop Event Request](https://opentransportdata.swiss/de/cookbook/open-journey-planner-ojp-landing-page/ojpstopeventrequest-2-0/)
- Trip Refinement Request
- [Trip Refinement Request](https://opentransportdata.swiss/de/cookbook/open-journey-planner-ojp-landing-page/ojptriprefinerequest-2-0/)

## Requirements
Compatible with Android 8+
Expand Down Expand Up @@ -69,6 +69,34 @@ requestLocationsFromCoordinates(
)
```

#### Get a list of sharing POIs within a bounding box (rectangle)
```
import ch.opentransportdata.ojp.OjpSdk

requestLocationsFromRectangle(
languageCode = LanguageCode.EN,
upperLeftLongitude = 7.431,
upperLeftLatitude = 46.945,
lowerRightLongitude = 7.446,
lowerRightLatitude = 46.950,
restrictions = LocationInformationParams(
types = emptyList(),
numberOfResults = 300,
ptModeIncluded = true,
modeFilter = ModeFilter(
exclude = false,
personalModes = listOf(
PersonalMode.BICYCLE,
PersonalMode.SCOOTER,
PersonalMode.CAR
)
)
)
)
```

The rectangle is defined by its upper left and lower right corners (WGS84) and is typically used to load shared mobility points of interest (e.g. e-scooters, bikes, cars) for the currently visible map region. Filter the results with a `ModeFilter` on `personalModes`. Each returned `PointOfInterest` exposes its category via `sharingCategories`. A `PointOfInterestFilter` (with `PointOfInterestCategory` / OSM tags) can be passed as well.

#### Get a list of trips
```
import ch.opentransportdata.ojp.OjpSdk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import ch.opentransportdata.ojp.data.dto.response.PlaceResultDto
import androidx.navigation.NavHostController
import ch.opentransportdata.presentation.feature.location.LirScreenComposable
import ch.opentransportdata.presentation.feature.map.MapScreen
import ch.opentransportdata.presentation.feature.map.SharedMobilityMapScreen
import ch.opentransportdata.presentation.feature.result.TripResultScreen
import ch.opentransportdata.presentation.feature.search.TripSearchScreen
import ch.opentransportdata.presentation.feature.stopevent.StopEventResultScreen
Expand All @@ -54,7 +55,7 @@ class MainActivity : ComponentActivity() {

@Composable
fun OjpDemoApp() {
val bottomNavigationItems = listOf(BottomNavItem.Lir, BottomNavItem.Tir, BottomNavItem.Ser)
val bottomNavigationItems = listOf(BottomNavItem.Lir, BottomNavItem.Tir, BottomNavItem.Ser, BottomNavItem.Map)
OJPAndroidSDKTheme {
val navController = rememberNavController()
var selectedBottomNavItem by remember { mutableIntStateOf(0) }
Expand Down Expand Up @@ -93,6 +94,7 @@ class MainActivity : ComponentActivity() {
composable<BottomNavItem.Lir> { LirNavHost() }
composable<BottomNavItem.Tir> { TirNavHost() }
composable<BottomNavItem.Ser> { SerNavHost() }
composable<BottomNavItem.Map> { SharedMobilityMapScreen() }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
Expand Down Expand Up @@ -75,15 +76,17 @@ fun LirScreenComposable(
}
}

state.value.events.forEach { event ->
when (event) {
is LocationViewModel.Event.ShowSnackBar -> {
coroutineScope.launch {
snackBarHostState.showSnackbar(message = event.message)
LaunchedEffect(state.value.events) {
state.value.events.forEach { event ->
when (event) {
is LocationViewModel.Event.ShowSnackBar -> {
coroutineScope.launch {
snackBarHostState.showSnackbar(message = event.message)
}
}
}
viewModel.eventHandled(event.id)
}
viewModel.eventHandled(event.id)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package ch.opentransportdata.presentation.feature.map
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import ch.opentransportdata.ojp.data.dto.response.GeoPositionDto
import org.maplibre.android.geometry.LatLng
import org.maplibre.android.maps.Style
import org.ramani.compose.CameraPosition
import org.ramani.compose.MapLibre
import org.ramani.compose.MapStyle
import org.ramani.compose.Polyline
import org.ramani.compose.rememberCameraPositionState

/**
* Created by Nico Brandenberger on 04.11.2025
Expand All @@ -25,22 +24,20 @@ fun MapScreen(
) {
val styleUrl = "https://vectortiles.geo.admin.ch/styles/ch.swisstopo.basemap.vt/style.json"
val mapLibrePoints = coordinates.map { LatLng(it.latitude, it.longitude) }
val cameraPosition = rememberSaveable {
mutableStateOf(
CameraPosition(
target = mapLibrePoints.first() ,
zoom = zoom,
)
val cameraPositionState = rememberCameraPositionState(
CameraPosition(
target = mapLibrePoints.first(),
zoom = zoom,
)
}
)
Surface(
modifier = Modifier.fillMaxSize(),
color = Color.Red
) {
MapLibre(
modifier = Modifier.fillMaxSize(),
styleBuilder = Style.Builder().fromUri(styleUrl),
cameraPosition = cameraPosition.value
style = MapStyle.Uri(styleUrl),
cameraPositionState = cameraPositionState
) {
Polyline(points = mapLibrePoints, color = "Red", lineWidth = 1.0F)
}
Expand Down
Loading
Loading