11 weeks 6 days ago
—
Nutiteq is proud sponsor of StateOfTheMap 2010 #sotm10
Hi,
i have a question. Is it possible downloading Open Street Map tiles while i'm showing the map to the user in the device? Because i want to have the maps offline but i don't know what map is going to need the user until he choose a city.
Thanks
Yes, that is what i want, but i don't really know how can i tell to the Nutiteq Map that it must use the downloaded tiles in the SDCard instead downloading them.
Thanks
Following code controls also that not too much
of space is taken for the cache:
final MemoryCache memoryCache = new MemoryCache(1 * 1024 * 1024); // 1MB
// final File cacheDir = this.getCacheDir(); // maybe it is not safe to use it
final File cacheDir = new File("/sdcard/maps_lib_cache");
if (!cacheDir.exists()) {
cacheDir.mkdir();
}
if(cacheDir.exists()){
StatFs statFs = new StatFs(cacheDir.getAbsolutePath());
int freespace = statFs.getAvailableBlocks() * statFs.getBlockSize();
Log.debug("Free space of " + cacheDir.getAbsolutePath() + " is "
+ freespace);
int cacheSizeWish = 10 * 1024 * 1024; // 10 MB
// do not take more than 50% of free space for caches
int cacheSize = (cacheSizeWish * 2) >= freespace ? (int) freespace / 2
: cacheSizeWish;
Log.debug("File cache set to " + cacheSize);
final AndroidFileSystemCache fileSystemCache = new AndroidFileSystemCache(
this, "network_cache", cacheDir, cacheSize);
mapComponent.setNetworkCache(new CachingChain(new Cache[] {
memoryCache, fileSystemCache }));
}else{
mapComponent.setNetworkCache(new CachingChain(new Cache[] {
memoryCache}));
}
I do not get fully what you want to get. Perhaps you should download tiles in parallel with map showing inside the application. Library does not have specific downloader for this.
You can also define permanent cache to the SD card, so next time map does not need to be downloaded.
/JaakL