Location Tracking

The Data Cloud Module for the Engagement Mobile SDK supports location tracking for all events. Enable this functionality using the setLocation method on the Data Cloud Module to set coordinates and expiresIn.
iOS
1// prepare the coordinates, use the CdpCoordinates wrapper
2let coordinates = CdpCoordinates(latitude: 54.187738, longitude: 15.554440)
3          
4// set the location coordinates and expiration time in seconds
5CdpModule.shared.setLocation(coordinates: coordinates, expiresIn: 60)
Android
1CdpSdk.requestSdk { sdk >
2    // prepare the coordinates, use the Coordinates wrapper
3    val coordinates = Coordinates(latitude = 54.187738, longitude = 15.554440)
4    
5    // set the location coordinates and expiration time in seconds
6    sdk.setLocation(coordinates = coordinates, expiresIn = 60) 
7}

Given that the SDK has non-expired location coordinates, the location attributes are automatically appended to the event attributes key value pairs with key names latitude and longitude.

When the expiration interval has been exceeded, the SDK location coordinates are cleared and longer attached to events. To prevent location from being attached to events before the coordinates expire, call setLocation and pass nil values as the coordinates.

You’re responsible for handling location tracking permission from the customer, requesting location permission, fetching the location, and ensuring the desired accuracy range.

Note