Reverse geocoding

VERSION 0.2.1455

Reverse geocoding means converting coordinates to human-readable information. The most common use case is retrieving an address, but the Search SDK can also return more detailed information such as speed limits, postal codes, or road numbers.


To use reverse geocoding, ensure the Search SDK has been added to the project. You can find out how to add it in the Project set up guide.

To access the reverse geocoding module, add TomTomSDKReverseGeocoder and TomTomSDKOnlineReverseGeocoder dependencies into Podfile.

1target 'YourAppTarget' do
2 use_frameworks!
3 pod 'TomTomSDKReverseGeocoder'
4 pod 'TomTomSDKOnlineReverseGeocoder'

Next, set the API key to GoReverseGeocoderService.reverseGeocoderKey and then initialize TomTomOnlineReverseGeocoderService, which is the entry point for online reverse geocoding requests.

ReverseGeocoderOnlineService.reverseGeocoderKey = "GEOCODER_KEY"

Making a reverse geocoding call

Specify the reverse geocoding request parameters with the ReverseGeocoderQuery class, either directly or by using ReverseGeocoderQuery.Builder. The only mandatory parameter for the call is the CLLocationCoordinate2D of the position to get more information about. You can also set optional parameters to obtain more details about the location. A detailed description of all the parameters can be found in the Reverse Geocoding documentation.

1let coordinate = CLLocationCoordinate2D(latitude: 52.366425, longitude: 4.908645)
2let builder = try? ReverseGeocoderQuery.Builder(position: coordinate)
3 .with(radius: 1000)
4 .with(heading: 90)
6guard let query = try? builder?.build() else {
7 // Handle the incorrect result of building query
8 return

Once the TomTomOnlineReverseGeocoderService and ReverseGeocoderQuery objects are initialized, you can perform a reverse geocoding. Parameter completion: The completion closure is called after the response to the request has been processed. If no errors occurred, ReverseGeocoderResponse contains addresses that match the geocoding request.

To make a request, initialize the TomTomOnlineReverseGeocoderService as shown in the following code example:

let reverseGeocoderApi = TomTomOnlineReverseGeocoderService()

Here is a sample reverse geocoder request:

1reverseGeocoderApi.reverseGeocoder(query: query) { result in
2 // Here you can get the first address of the recognized place.
3 guard case let .success(response) = result,
4 let address = response.places.first?.place.address else {
5 return
6 }