Reverse geocoding

VERSION 0.3.34
PUBLIC PREVIEW

The Reverse Geocoding module translates a coordinate (37.786505, -122.3862) into human-understandable information like a street address or street element ("30 The Embarcadero, San Francisco, CA 94111"). Tracking applications use this tool to receive a GPS feed from a device or asset and obtain the corresponding address.

The type of response depends on the available data:

  • address: Returns the most detailed information.
  • street element: Less detailed; returned when there is no address data.
  • geography: Returns the smallest available geographic data.
    • This is returned when there is no address or street element data.
    • You can specify the level of geography to get a geometry (see the entityTypes parameter).

Initializing

To use the Reverse Geocoding SDK, you need to configure its credentials and add the SDK as a dependency:

  1. Get your TomTom API Key and configure the project as described in the Project setup guide.
  2. Add the Reverse Geocoding module dependency in the build.gradle of your application module and synchronize the project.
    1dependencies {
    2 implementation "com.tomtom.sdk:reverse-geocoding-client-api:0.3.34"
    3 implementation "com.tomtom.sdk:reverse-geocoding-client-online:0.3.34"
    4}

After synchronizing the project, initialize the ReverseGeocoderApi interface. This interface is the entry point to using TomTom’s Reverse Geocoding SDK. There can be multiple implementations of this interface. However at this moment the only implementation of this interface is OnlineReverseGeocoderApi.

val reverseGeocoderApi: ReverseGeocoderApi = OnlineReverseGeocoderApi.create("YOUR_API_KEY")

Making a reverse geocoding call

Specify the reverse geocoding request parameters with the ReverseGeocoderOptions class. The only mandatory parameter for the call is the position of the location for which you want to obtain an address. You can also set optional parameters to request more data, like geometry or road use and speed limits. A detailed description of all the parameters can be found in the Reverse Geocoding documentation.

1val coordinate = GeoCoordinate(52.37650747883495, 4.908392018265384)
2val reverseGeocoderOptions = ReverseGeocoderOptions(
3 position = coordinate,
4)

Once you have a ReverseGeocoderOptions object, provide it to the reverse geocoding request. This can be done asynchronously using the ReverseGeocoderCallback, or synchronously as described in Synchronous search call. If the call succeeds, the returned result is in ReverseGeocoderResponse. If an error occurred, it is in ReverseGeocoderError.

1reverseGeocoderApi.reverseGeocode(reverseGeocoderOptions, object : ReverseGeocoderCallback {
2 override fun onSuccess(result: ReverseGeocoderResponse) {
3 /* YOUR CODE GOES HERE */
4 }
5
6 override fun onError(error: ReverseGeocoderError) {
7 /* YOUR CODE GOES HERE */
8 }
9})

Reverse Geocoding