Map API

Nutiteq Maps Lib SDK enables developing advanced mobile mapping applications.
Platforms: Android, RIM BlackBerry, Java ME (J2ME)
Download maps API SDK »
Untitled Document

Products

» View demos
» Downloads

Uudised

Viimane: Tue, 17 May 2011 13:21:59
Teema: Nutimap Eesti kaardi asemele
Veel uudiseid »

Android Download Map Tiles

11 replies [Last post]
xger86x
User offline. Last seen 1 year 44 weeks ago. Offline
Joined: 02/11/2010

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

FailinimiSuurus
CloudMade.java3.74 KB
jaak
User offline. Last seen 11 hours 17 min ago. Offline
Joined: 06/19/2008

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

xger86x
User offline. Last seen 1 year 44 weeks ago. Offline
Joined: 02/11/2010

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

jaak
User offline. Last seen 11 hours 17 min ago. Offline
Joined: 06/19/2008

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}));
            }

/JaakL

Kishore
User offline. Last seen 49 weeks 2 days ago. Offline
Joined: 01/31/2011

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?

Regards,
Kishore

Kishore
User offline. Last seen 49 weeks 2 days ago. Offline
Joined: 01/31/2011

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

Regards,
Kishore

Kishore
User offline. Last seen 49 weeks 2 days ago. Offline
Joined: 01/31/2011

Hi All,

How to display the tiles back from /sdcard/maps_lib_cach onto Map, when offilne??

Thanks,
Kishore

Regards,
Kishore

jaak
User offline. Last seen 11 hours 17 min ago. Offline
Joined: 06/19/2008

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?

/JaakL

giordano
User offline. Last seen 14 weeks 1 day ago. Offline
Joined: 07/29/2011

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:

  1. get a set of map tiles at home about one path of interest,
  2. travel to go on place, a place where you can work exclusively offline and, at the end,
  3. follow the path with the help of the cached tiles and the their GPS position.
  4. 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();
    //...
    }
    }

jaak
User offline. Last seen 11 hours 17 min ago. Offline
Joined: 06/19/2008

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).

/JaakL

giordano
User offline. Last seen 14 weeks 1 day ago. Offline
Joined: 07/29/2011

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

jaak
User offline. Last seen 11 hours 17 min ago. Offline
Joined: 06/19/2008

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.

/JaakL