Skip to content

Display Current Street Name

In this guide you will learn how to display the street name for the current position on the map of the green arrow/device position indicator.

Setup

First, get an API key token, see the Getting Started guide.

Download the Maps & Navigation SDK for Android archive file

Download the DisplayCurrentStreetName project archive file or clone the project with Git

See the Configure Android Example guide.

Run the example

In Android Studio, from the File menu, select Sync Project with Gradle Files

An android device should be connected via USB cable.
Press SHIFT+F10 to compile, install and run the example on the android device.

Display current street name example Android screenshot

Display current street name example Android screenshot

Display current street name example Android screenshot

The map is loaded, showing the current position of the device using the green arrow GPS position indicator. The name of the current street is displayed in the black text box at the bottom of the screen. If the device is moving, the name of the street displayed is updated every time the devices moves onto a different street.

How it works

Android example screenshot

You can open the MainActivity.kt file to see how the current street name is obtained and displayed.

In the class MainActivity : AppCompatActivity(), an instance of
private val dataSourceListener = object : DataSourceListener() { is created.
The dataSourceListener automatically receives updates, such as changes in the device position.
override fun onNewData(dataType: EDataType) { } }
These updates are processed in the overridden onNewData() function within the dataSourceListener.
The road address, that is, street name, is obtained from the data source,
val roadAddress = improvedPositionData.roadAddress ?: return@execute and set along with the speed limit for the current segment
text += ", ${df.format(improvedPositionData.roadSpeedLimit)}"
text += ", ${improvedPositionData.roadModifier}"
in the text value displayed at the bottom of the screen.
 1SdkSettings.onMapDataReady = {
 2    val hasPermissions = PermissionsHelper.hasPermissions(this, permissions)
 3    if (hasPermissions) {
 4        SdkCall.execute {
 5            startImprovedPositionListener()
 6        }
 7    } else {
 8        requestPermissions(this)
 9    }
10}
The override fun onCreate() function calls the startImprovedPositionListener() function after the map is loaded.
1private fun startImprovedPositionListener() {
2    if (gemSurfaceView.mapView?.isFollowingPosition() != true)
3        gemSurfaceView.mapView?.followPosition()
4    if (dataSource == null)
5        dataSource = DataSourceFactory.produceLive()
6    dataSource?.addListener(dataSourceListener, EDataType.ImprovedPosition)
7}
This function causes the camera to start following the green arrow/device position indicator on the map if it is not already in follow/tracking mode.
gemSurfaceView.mapView?.followPosition()
Also it instantiates a connection to the dataSource, if not instantiated already,
dataSource = DataSourceFactory.produceLive()
and adds a listener, which will be called automatically every time new data is available, such as, for example, the position (longitude, latitude) of the device has changed.
dataSource?.addListener(dataSourceListener, EDataType.ImprovedPosition)

Android Examples

Maps SDK for Android Examples can be downloaded or cloned with Git