feat!: Application outline

This commit is contained in:
Piotr Dec 2024-07-23 00:55:59 +02:00
parent 80dfa6ab4e
commit 01fbf32042
Signed by: stawros
GPG key ID: F89F27AD8F881A91
9 changed files with 1440 additions and 190 deletions

View file

@ -0,0 +1,46 @@
package eu.ztsh.garmin.mapbox
import com.mapbox.common.location.Location
import com.mapbox.navigation.core.trip.session.LocationMatcherResult
import com.mapbox.navigation.core.trip.session.LocationObserver
import com.mapbox.navigation.ui.maps.camera.transition.NavigationCameraTransitionOptions
class LocationObserver(private val mapControl: MapControl) : LocationObserver {
/**
* Gets notified with location updates.
*
* Exposes raw updates coming directly from the location services
* and the updates enhanced by the Navigation SDK (cleaned up and matched to the road).
*/
private var firstLocationUpdateReceived = false
override fun onNewRawLocation(rawLocation: Location) {
// not handled
}
override fun onNewLocationMatcherResult(locationMatcherResult: LocationMatcherResult) {
val enhancedLocation = locationMatcherResult.enhancedLocation
// update location puck's position on the map
mapControl.navigationLocationProvider.changePosition(
location = enhancedLocation,
keyPoints = locationMatcherResult.keyPoints,
)
// update camera position to account for new location
mapControl.viewportDataSource.onLocationChanged(enhancedLocation)
mapControl.viewportDataSource.evaluate()
// if this is the first location update the activity has received,
// it's best to immediately move the camera to the current user location
if (!firstLocationUpdateReceived) {
firstLocationUpdateReceived = true
mapControl.navigationCamera.requestNavigationCameraToOverview(
stateTransitionOptions = NavigationCameraTransitionOptions.Builder()
.maxDuration(0) // instant transition
.build()
)
}
}
}