Mobile SDK allows you to create mobile apps over the CARTO platform.
This component is still under support but it will not be further developed. We don’t recommend starting new projects with it.
Offline maps, routing and geocoding in the CARTO Mobile SDK require that you pre-download map data. For this we provide SDK internal API called PackageManager - this manages offline data packages, which are downloaded from CARTO server and used by the SDK for specific features.
So for offline mapping (geocoding or routing) you need to
The packages that are once downloaded are kept persistently on the device and can be updated or removed through the PackageManager as the app requires.
When creating PackageManager, you specify package contents by setting source parameter value as following:
carto.streets map data packages (vector tiles) for visual map layer.routing:nutiteq.osm.car - routing data packages for OSRM routing engine and car profilerouting:carto.streets - routing data packages for Valhalla routing engine (deprecated in SDK 4.2)geocoding:carto.streets - geocoding/address search data packagesAll these sources are based on OpenStreetMaps map data.
App has to decide to which folder the map files are stored. Typically you use standard file locations there, depending on platform. Note that each package source ID should be stored in a different folder, e.g. mappackages, routingpackages, geocodingpackages.
Package downloads for country packages cannot be started immediately, as the Mobile SDK needs to get latest definition of packages from CARTO online service. Once this list is received, PackageManagerListener’s onPackageListUpdated() is called.
Therefore you should write your own PackageManagerListener, and start package download using the onPackageListUpdated method, which ensures that the package metadata is downloaded.
You see that onPackageListUpdated() callback starts immediately download of some packages, as we are quite impatient here. Real download starts when initialization is done and PackageManager is started.
To link PackageManagerListener with PackageManager, apply the following code.
To have offline map data the PackageManager has to download some maps. Thre are two types of offline downloads: code sample above already includes downloading for country ID-s, and you can download also offline maps for any custom areas e.g. cities.
During any package download PackageManagerListener gets onPackageStatusChanged() call back events, this can be used to display progress bar UI.
Se list of available ID-s: https://github.com/CartoDB/mobile-sdk/wiki/List-of-Offline-map-packages
Start download of e.g. Estonia with this PackageManager use method: .startPackageDownload("EE");. Note that you must be sure that the PackageList is downloaded at least once: this is started with .startPackageListDownload() and confirmed in onPackageListUpdated() callback.
CARTO Mobile SDK allows for the download of custom areas, called bounding boxes. It can be a city or national park for example. Note that there is size limit of about 50x50 km for the allowed areas here. For bigger areas you need to use several downloads, or country package.
A bounding box is constructed as bbox(west longitude,south latitude,east longitude,north latitude, so the bounding box of Berlin would be: bbox(13.2285,52.4698,13.5046,52.57477). There is no separate method for bounding box download start, just use same as string instead of instead of a country or county code, as package ID. So Berlin download would start with .startPackageDownload("bbox(13.2285,52.4698,13.5046,52.57477)");
Note that if you only download bounding box areas in your app, then PackageListDownload is not needed.
You should add CartoOfflineVectorTileLayer to the MapView, using PackageManager and map style for offline map layer as constructor parameters.
Warning - until map is downloaded, then this layer will have no map. So you may want to add another online tiled layer with same style, which will be replaced once offline map is downloaded
1
2
3
CartoOfflineVectorTileLayer layer = new CartoOfflineVectorTileLayer(cartoPackageManager, CartoBaseMapStyle.CARTO_BASEMAP_STYLE_VOYAGER);
mapView.getLayers().add(layer);
Offline Routing is covered in our Offline Routing document
Offline geocoding is covered in our Offline Geocoding document
There is no special event or method to check package updates, so updates can be checked and controlled by application using following logic. You can call this logic as soon as you feel appropriate. Different packages can be updated in different point of time, and with different frequency.
During re-download of same package application shows old map until download is complete. So the update can run in background safely.