我试图在MapBox中缓存地图。当应用程序在网上,一切正常。tileCacheDidFinishBackgroundCache正在被正确地调用。
然后,我重新启动应用程序离线。而不是地图,RMMapView只显示白色。
我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
[[RMConfiguration sharedInstance] setAccessToken:@"pk......"];
RMTileCache * tileCache = [[RMTileCache alloc] initWithExpiryPeriod:0];
[tileCache setBackgroundCacheDelegate:self];
tileSource = [[RMMapboxSource alloc] initWithMapID:@"mirap.ld8dbe2c"];
mapView = [[RMMapView alloc] initWithFrame:viewMapView.bounds
andTilesource:tileSource];
[mapView.tileSource setCacheable:YES];
[viewMapView addSubview:mapView];
}
-(void)viewDidAppear:(BOOL)animated {
RMSphericalTrapezium rect = [mapView latitudeLongitudeBoundingBox];
mapView.tileCache.backgroundCacheDelegate = self;
[mapView.tileCache beginBackgroundCacheForTileSource:mapView.tileSource
southWest:rect.southWest
northEast:rect.northEast
minZoom:10.0
maxZoom:20.0];
}
- (void)tileCacheDidFinishBackgroundCache:(RMTileCache *)tileCache {
NSLog(@"DONE!");
}发布于 2015-04-16 23:27:38
以下是你所需要的:
mapbox-ios-sdk-offline/ViewController.swift#L38-L44
简而言之,用映射ID初始化一个平铺源是请求远程元数据URL的缩写。
-[RMMapboxSource initWithMapID:]
此方法需要网络连接才能下载用于定义瓷砖源的TileJSON。
相反,您还希望缓存tileSource.tileJSON并在脱机时使用它初始化瓷砖源。
用于本地保存以便用于脱机时实例化瓷砖源。
https://stackoverflow.com/questions/29658607
复制相似问题