You can calculate the length of time it will take to travel between the user’s location and another location in your app using a range of transportation types. First you will need to detect the user location, then you can calculate the time to travel from it to the target location, which can come from another source in your app, such as API data.
On iOS, you will first need to use the Request Location Authorization Action, specifying a Page Variable of type CLLocationManager that you will reference in the Action that calculates travel time. On Android, requesting location permission is handled automatically.
- Create a Page Variable for the target location, choosing type CLLocation (iOS) / LatLng Android. Save the target location to the variable, for example using a Create a Location/LatLng Object Action and a Set Value Action.
- Retrieve the user location with a Request Location Update Action (unless you’re using Start Tracking Location, in which case you can retrieve the location from a CLLocationManager (iOS) / DSLocationTracker Page Variable).
- When you have an up to date location for the user (e.g. in the nested Location Updated Event of the Request Location Update Action), add the Calculate Travel Time (iOS) / Calculate Distance and Travel Duration (Android) Action. For the Source, select the updated user location – from the Event Data if you’re in a Location Updated Event, or the location tracker/manager Page Variable if you’re tracking the user location continuously. For the Destination, select the target location Page Variable you created. Choose a transportation type.
Your app can also calculate distance and can determine the closest in an array of locations. You can also use the math Action to carry out numeric calculations in your apps.