Offline caching using the MapBox Android SDK

I have a working prototype of iOS using the iOS caching technique as shown below (Objective-C code):

RMTileCache  * tileCache = [[RMTileCache alloc] initWithExpiryPeriod:0]; 
[tileCache setBackgroundCacheDelegate:self]; 
RMMapboxSource * tileSource = [[RMMapboxSource alloc] initWithMapID:mapID]; 
[tileCache beginBackgroundCacheForTileSource:tileSource southWest:southWest northEast:northEasth minZoom:minZoom maxZoom:maxZoom];

Basically this is loading the map, caching tiles forever and the ability to launch the application offline in the future. As we go through the official paid API, this, of course, does not violate any legal restrictions.

Now I would like to achieve the same on Android. I have an SDK running in Android Studio and a working project with a remote card using a card id, basically this (Eclipse format for Android XML):

<com.mapbox.mapboxsdk.views.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    mapid="my_map_id" />

This works fine, but the solution should be completely disabled after caching is complete. My question is: is there a Java equivalent of the iOS source code above in the MapBox SDK? I tried to look in the API, but could not find a reliable link to the plate caching system. And after some painful time, trying to get it to work based on method names and code documentation, I gave up.

I run the latest MapBox distribution from GitHub along with the latest version of Android Studio, everything works fine, but I can not find the code for this. I don't necessarily need an API link, a few lines of code showing how to do it would be enough.

+4
source share
3 answers

SDK Mapbox Android 0.5.1. 20 2014 . , :

OfflineMapDownloader offlineMapDownloader = OfflineMapDownloader.getOfflineMapDownloader(getActivity());
BoundingBox boundingBox = mapView.getBoundingBox();
CoordinateSpan span = new CoordinateSpan(boundingBox.getLatitudeSpan(), boundingBox.getLongitudeSpan());
CoordinateRegion coordinateRegion = new CoordinateRegion(mapView.getCenter(), span);
offlineMapDownloader.beginDownloadingMapID("MapboxMapID", coordinateRegion, (int) mapView.getZoomLevel(), (int) mapView.getZoomLevel());

:

ArrayList<OfflineMapDatabase> offlineMapDatabases = offlineMapDownloader.getMutableOfflineMapDatabases();
OfflineMapDatabase db = offlineMapDatabases.get(0);
OfflineMapTileProvider tp = new OfflineMapTileProvider(getActivity(), db);
offlineMapOverlay = new TilesOverlay(tp);
mapView.addOverlay(offlineMapOverlay);
+9

, :

" Android SDK , .

- support@mapbox.com "

, , Android.

+2

:

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

, MapView:

File file = new File("your full path to tiles db");
MBTilesLayer mbTilesLayer = new MBTilesLayer(file);
MapView mapView = (MapView) findViewById(R.id.yourMapViewId);
mapView.setTileSource(mbTilesLayer);
0

Source: https://habr.com/ru/post/1527912/


All Articles