Search code examples
androidkotlinosmdroid

Osmdroid & Osmdroid bonuspack how to use CacheManager


 val cm= CacheManager(map)
    val  mt=MapTile(map.getZoomLevel(),map.scrollX,map.scrollY);
    //(cm.loadTile(TileSourceFactory.MAPNIK,mt)) 
     cm.downloadAreaAsync(this,bb,map.minZoomLevel,map.maxZoomLevel);

So that's how I download OSM loaded map! now i want that next time when the application opened it'll direct load the map from local already cached source rather than going to online/network request.


Solution

  • You shouldn't have to do anything, it's automatic. The cache manager basically hooks into the MapView's IFileSystemCache provider, which by default is the sqlite database. However keep the following in mind.

    • Unless you change the default map provider instance, the cache is always hit first. If a needed tile is expired, it will attempt to redownload.
    • Tile expiration times are set the server and can vary per tile, significantly
    • It's possible to extend the expiration time and/or override the expiration time stamp using osmdroid's Configuration class structure
    • It's also possible to create a permanent tile archive on device using the cache manager. There are legal, terms of service, moral and potential ethical issues with this. Make sure you read the file print for the tiles sources you make available to your users.

    Also, be advised that the cache manager is now located in the osmdroid-android library due to a partial merge with history with osmbonuspack. See the change log and upgrade guide for more information