Location tracking
The Navigation SDK UX Framework uses raw device location to power important navigation features including:
- Enhancing location updates and snapping them to the road graph.
- Determining which instruction to show next, and when to show it, based on where the user is along the route.
- Detecting when the driver has deviated from the current route, prompting the SDK to generate a new route to get them back on track.
- Proactively downloading map tiles and routing information ahead of the driver's current location in case the driver enters an area with no or poor network connection.
To receive location updates while the trip session is running, you can observe them through Dash.controller
instance.
**Raw location. **This is a location event that contains unprocessed (as it comes from the location provider) location. These events are emitted as soon as a new location has been received:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
Dash.controller.observeRawLocation()
.collect { /* Location */ location ->
// Do something with the Location
}
}
}
}
}
Enhanced location. This event contains a location enhanced (processed and map matched) by the UX Framework. It gets invoked when a new Raw Location is snapped to the route or map matched to the road. It can be accessed via LocationMatcherResult
:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
Dash.controller.observeLocationMatcherResult()
.collect { /* LocationMatcherResult */ result ->
// Do something with the LocationMatcherResult
val enhancedLocation = result.enhancedLocation
}
}
}
}
}
この{Type}は役に立ちましたか?