Reverse geocoding
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.
Project setup
To use reverse geocoding, ensure the Search SDK has been added to the project.
- Configure the project as described in the project setup guide.
To access the reverse geocoding module, add TomTomSDKReverseGeocoder
and TomTomSDKReverseGeocoderOnline
modules to your project’s Podfile
.
1TOMTOM_SDK_VERSION = '0.28.2'23target 'YourAppTarget' do4 use_frameworks!5 pod 'TomTomSDKReverseGeocoder', TOMTOM_SDK_VERSION6 pod 'TomTomSDKReverseGeocoderOnline', TOMTOM_SDK_VERSION7end
- Install the dependencies by executing the following commands in the project directory:
pod repo-art update tomtom-sdk-cocoapodspod install --repo-update
Initialing reverse geocoding
- Initialize the
OnlineReverseGeocoder
, which is the entry point for online reverse geocoding requests:
let reverseGeocoderApi = OnlineReverseGeocoder(apiKey: "YOUR_API_KEY")
Making a reverse geocoding call
Specify the reverse geocoding request parameters with the ReverseGeocoderOptions
struct. 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 options = ReverseGeocoderOptions(3 position: coordinate,4 heading: Measurement.tt.degrees(90),5 radius: Measurement.tt.meters(1000)6)
Once the OnlineReverseGeocoder
and ReverseGeocoderOptions
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.
Here is a sample reverse geocoder request:
1reverseGeocoderApi.reverseGeocode(options: options) { result in2 // 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 return6 }7}