Location context


Navigation SDK for Android is only available upon request. Contact us to get started.

While navigating, you can retrieve detailed information about the current location on the road using LocationContext.

The SDK provides location context data such as:

  • The current speed
  • The speed limit
  • The properties of the road (for example, the number of lanes, the functional road class or the driving side)
  • The address (for example, the name of the city, the name of the street or the number on the street).

Refer to the LocationContext API reference for more details.

This guide explains to you how to use LocationContext to retrieve the name of the city and the name of the street at the current location.

Starting navigation

Before retrieving location context information, you need to start navigation with a route as described in the Starting navigation guide.

But, instead of adding a listener for route progress updates, make sure you add a LocationContextUpdatedListener to listen to location context updates.

1fun startNavigation() {
2 val tomTomNavigation = OnlineTomTomNavigationFactory.create(navigationConfiguration)
3 tomTomNavigation.addLocationContextUpdatedListener(locationContextUpdatedListener)
5 val routePlan = RoutePlan(route, routePlanningOptions)
6 val navigationOptions = NavigationOptions(routePlan)
7 tomTomNavigation.start(navigationOptions)

Retrieving location context information

With navigation started, you can listen to location context updates and retrieve the name of the city and the name of the street at the current location along the route.

1private val locationContextUpdatedListener =
2 object : LocationContextUpdatedListener {
3 override fun onLocationContextUpdated(locationContext: LocationContext) {
4 locationContext.address?.let { address ->
5 Log.v(TAG, "city name:" + address.municipality)
6 Log.v(TAG, "street name:" + address.streetName)
7 }
8 }
9 }

Next steps

Now that you know how to retrieve location context information, here are the recommendations on what to explore next: