Skip to content Skip to sidebar Skip to footer

Offline Tile Caching Using Mapbox Android Sdk

I have a working iOS prototype using the iOS tile-caching technique as shown below (Objective-C code): RMTileCache * tileCache = [[RMTileCache alloc] initWithExpiryPeriod:0]; [ti

Solution 1:

Offline Tile Caching support is now available in the Mapbox Android SDK as of version 0.5.1. It was released on 20-December-2014. Here's a basic example of how to get started:

OfflineMapDownloaderofflineMapDownloader= OfflineMapDownloader.getOfflineMapDownloader(getActivity());
BoundingBoxboundingBox= mapView.getBoundingBox();
CoordinateSpanspan=newCoordinateSpan(boundingBox.getLatitudeSpan(), boundingBox.getLongitudeSpan());
CoordinateRegioncoordinateRegion=newCoordinateRegion(mapView.getCenter(), span);
offlineMapDownloader.beginDownloadingMapID("MapboxMapID", coordinateRegion, (int) mapView.getZoomLevel(), (int) mapView.getZoomLevel());

To load a previously saved map:

ArrayList<OfflineMapDatabase> offlineMapDatabases = offlineMapDownloader.getMutableOfflineMapDatabases();
OfflineMapDatabasedb= offlineMapDatabases.get(0);
OfflineMapTileProvidertp=newOfflineMapTileProvider(getActivity(), db);
offlineMapOverlay = newTilesOverlay(tp);
mapView.addOverlay(offlineMapOverlay);

Solution 2:

I asked this question to the support team, here's the answer:

"We don't currently have a release date for the Android SDK or for this feature, because both are in very early stages of development.

-- Tom MacWright support@mapbox.com"

It's a very good product, I hope we can use it soon in Android.

Solution 3:

In your layout file there must be:

<com.mapbox.mapboxsdk.views.MapView
        android:id="@+id/yourMapViewId"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

In code where you want to initialize MapView:

Filefile=newFile("your full path to tiles db");
MBTilesLayermbTilesLayer=newMBTilesLayer(file);
MapViewmapView= (MapView) findViewById(R.id.yourMapViewId);
mapView.setTileSource(mbTilesLayer);

Post a Comment for "Offline Tile Caching Using Mapbox Android Sdk"