Routing is the navigation from a defined start location to a defined end location. The calculated results are displayed as turn-by-turn directions on your map, based on the transportation mode that you specified. Routing functionality through the Mobile SDK includes online routing, based on CARTOs online service, and offline routing, which requires that you install an offline data package on your local device.
Mobile SDK supports the following routing features:
- Find the fastest route from A to B
- Find the fastest route between X points, in a given order
- Get the complete result by route geometry and display it on the map
- Set instructions for navigation actions (turn left/right, u-turn, leave roundabout etc.)
- Specify instruction details, such as the street name, turn angle, azimuth, distance and time for the next leg
- Plan for turn restrictions and one-way streets as part of the route
- Fast calculations in new devices, approximately 200-300 ms is expected, even for long routes
- Multi-country route calculations
Mobile Routing is optimized for low memory usage and calculation speed, including very large road networks using Contraction Hierarchy representation and algorithms. As a result, this creates some expected limitations:
Route profile is precalculated from the server and hardcoded in the data. For different profiles, such as driving or walking, download different map data packages to accomodate for offline routing
There is no shortest or fastest choice in the calculation, this is pre-coded in the routing data
There are no alternative routes provided
There is no live data in routing, traffic and temporarily closed roads do not appear
Note: Routing does not include live navigation features, such as following a GPS location, initiating automatic recalculations, or guided voice instructions. However, these features can be built on top of routing by your device application.
For minimal routing implementation, use our sample app code for different mobile platforms. You can add this sample code to your mobile project.
Xamarin (Android, iOS):
The following procedure describes how to apply the sample routing code in your mobile app project.
Download the sample code to your mobile app project
The pre-coded, offline route packages are automatically loaded.
Tip: For this example, Estonia and Latvia are downloaded by default. You can easily change the code to download any other country or state.
Press and hold (long-click) on map to set route start point. Long-click a second time to set the end point
Tip: See Listening to Events for details about the
Once the end-point is set, the route is automatically calculated
The route is shown as a line on map, and the navigation instructions appear as markers
See this video demonstration of how routing appears in a mobile app.
Note the following simplifications applied within the sample code You may need to adjust your code accordingly if want to apply different options:
The background map is online
Online routing is applied before any offline routing is completed. For offline routing, wait a few minutes until the download finishes. The download progress is not indicated in the app
To prevent routing errors, ensure the route start and end points are within the downloaded package areas. If the shortest route passes another country or area that is not downloaded, routing fails
If the route start and route stop points are in located in different countries, you must also find and download each country package that will appear along the route
The following Online Routing and Offline Routing procedures demonstrate the required routing code.
Online routing requires that you create a simple call and request to calculate the route.
1) Create the
2) Calculate the route with the
Calculating routing requests are expensive (in quota consumption and in processing times). It is recommended to use a background task for more efficient performance. Otherwise, the original routing task can be blocked for a few seconds on slower mobile devices.
These code samples display how to show navigation instructions on the map, as indicated by line and markers.
Offline routing requires a more complicated preparation of your offline map packages, listener events, package initialization, and routing calculation parameters.
First, you need to initialize a package manager and a listener to download packages. View the PackageManager documentation to find more about offline packages.
If all routing packages are downloaded and routing service is ready, you can calculate routing.
RoutingRequestwith at least two points. Start routing with the service and read response as RoutingResult.
Calculate the route with the
Note: This step is identical to the online routing calculation code.
CARTO has created a customized routing package, similar to other offline map packages, that contain world-wide offline route packages. This routing package includes the corresponding online service for most common profiles, using osm.car and osm.foot OpenStreetMap data, as the map source.
The list of country packages for routing is the same as other offline maps. See Offline Map Packages for the full list of offline packages
The download size of the offline routing package is significantly larger (10-40% greater) than the size of the corresponding offline map package. Car profile packages are considerably smaller than walking packages
For Enterprise accounts, offline routing packages can include an extra agreement to include HERE.com map data. In many countries, especially outside Europe, offline routing packages contain more granular results. In addition, HERE includes address data. Please contact us if you are interested in extra Enterprise mobile features