Closed huynhduyson closed 8 years ago
How do you initialize your RMTileCache
? Do you use the same map source for the online/offline map? Sharing some code of your setup would be helpful.
Thanks @Svantulden Here is my source code:
- (void)viewDidLoad {
[super viewDidLoad];
maxDownloadZoom = 15;
minDownloadZoom = 9;
[[RMConfiguration configuration] setAccessToken:@"pk.eyJ1IjoianVzdGluIiwiYSI6IlpDbUJLSUEifQ.4mG8vhelFMju6HpIY-Hi5A"];
RMMapboxSource *tileSource = nil;
NSString *tileJSON = [[NSUserDefaults standardUserDefaults] objectForKey:@"tileJSON"];
if(tileJSON){
tileSource = [[RMMapboxSource alloc] initWithTileJSON:tileJSON];
}
else {
tileSource = [[RMMapboxSource alloc] initWithMapID:@"mapbox.streets"];
}
if (tileSource == nil) {
NSLog(@"The app requires a first run while online.");
}
else {
map = [[RMMapView alloc] initWithFrame:self.view.bounds andTilesource:tileSource];
map.delegate = self;
[map setZoom:minDownloadZoom atCoordinate:map.centerCoordinate animated:false];
map.maxZoom = maxDownloadZoom;
map.tileCache = [[RMTileCache alloc] initWithExpiryPeriod:0];
map.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:map];
}
}
- (void)downloadCache {
// update cached TileJSON metadata for tile source
RMMapboxSource *source = (RMMapboxSource *)map.tileSource;
NSString *tileJSON = source.tileJSON;
[[NSUserDefaults standardUserDefaults] setObject:tileJSON forKey:@"tileJSON"];
[[NSUserDefaults standardUserDefaults] synchronize];
map.tileCache.backgroundCacheDelegate = self;
[map.tileCache beginBackgroundCacheForTileSource:map.tileSource
southWest:map.latitudeLongitudeBoundingBox.southWest
northEast:map.latitudeLongitudeBoundingBox.northEast
minZoom:minDownloadZoom maxZoom:maxDownloadZoom];
}
Download Tiles in range: minimum zoom is 9, maximum zoom is 15. When I turn of Wifi and cellular data, sometime the map only show Tiles with zoom 13,14,15.
I have found out the cause. Default RMDatabaseCache's capacity is 1000 while the number of tiles I downloaded exceed 1000. Thanks for your support.
Ah, great that you found it! That was what I needed to do as well indeed.
I've been able to download offline map areas in the cache, however it seems the cache is not accessed when I turn of Wifi and cellular data. The Map Tiles are not coming up. Only the Map Tiles that were automatically cached are showing.