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
| Failinimi | Suurus |
|---|---|
| CloudMade.java | 3.74 KB |
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}));
}
Hi,
The above code is to get the Cache memory size for storing images/tiles. But how to download the tiles from the Map and how to store in the memory cache?
Hi,
After downloading the tiles, its stored in /sdcard at a predefined path. Now how to display back the tiles as Maps when n/w is not available???
Thanks,
Kishore
Hi All,
How to display the tiles back from /sdcard/maps_lib_cach onto Map, when offilne??
Thanks,
Kishore
Cache is used automatically - if device is offline then it should read map from the cache, and only maps which are not there are read on-line. Currently you cannot force to use only cache, maybe you seek something like this?
Hi to all.
I've tried to implement the solution of Jaak, with a little variation to record the map tiles on the internal memory.
The result is that the tiles come recorded in the cache and all works fine. While I see new portions of the map, I noticed that the data size of my app grow, properly.
If I turn off and then turn on the device I see that the data of my app are of the same size as before the shutdown. But if I'am in offline mode and I start my app, I don't see none of the tiles that I' have seen, and hence cached, before of the shutdown.
For the purpose of my app it's not acceptable. My users need to:
Please help me to satisfy the users of my app.
Thanks in advance, best regards.
PS: follows the code that I've used to set the map caching
public class FirstActivity extends Activity {
//...
private MemoryCache memoryCache;
private CachingChain cachingChain;
//...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
memoryCache = new MemoryCache(10 * 1024 * 1024); // 1MB
//...
File cacheDir = getDir("eguidesMapCache", Context.MODE_PRIVATE);
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 = 1000 * 1024 * 1024; // 1 GB
// 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);
this.setCachingChain(new CachingChain(new Cache[] {fileSystemCache }));
}else{
this.setCachingChain(new CachingChain(new Cache[] {memoryCache}));
}
//...
// Map initialization
this.theMap = new BasicMapComponent("myKey", new AppContext(this), 1, 1, new WgsPoint(0, 0),
9);
this.theMap.setMap(new CloudMade("myKey", "", 256, 1));
//...
this.theMap.setNetworkCache(this.getCachingChain());
this.theMap.startMapping();
//...
}
}
The problem is in the map type. CloudMade uses session IDs which are requested with another HTTP request on-line, and this is not cached. Two possible solutions:
a) Use some other map types (e.g. OpenStreetMap direct)
b) Use modified CloudMade map where also token request is persistently cached as in attached file to this post above (line 111 is changed).
Hi Jaak!
First of all thanks a lot for your rapid answer.
To understand completly what you have written, I've for you two question:
1. In the first solution, how can I use directly OpenStreetMap?
2. In the second solution, do I simply substitute the class com.nutiteq.maps.CloudMade with the one attached after the first post of this thread?
Thanks again for your effective and rapid answer and for your very useful and powerful library.
Best regards,
Giordano
1. mapComponent.setMap(OpenStreetMap.MAPNIK); You are then bound to http://wiki.openstreetmap.org/wiki/Tile_usage_policy, please check this also.
2. yes. You can put the file to your own app, then make sure that in setMap you refer to your application class and not to the one with same name in SDK. Also you probably need to add some imports to the CloudMade.java, something like import com.nutiteq.maps.* would do.
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