feat!: Application outline
This commit is contained in:
parent
80dfa6ab4e
commit
01fbf32042
9 changed files with 1440 additions and 190 deletions
46
app/src/main/java/eu/ztsh/garmin/mapbox/LocationObserver.kt
Normal file
46
app/src/main/java/eu/ztsh/garmin/mapbox/LocationObserver.kt
Normal 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()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue