离线地图
为了节约流量,可以将某省市的离线地图下载到手机SD卡中,在没有网络连接的情况下也能自由使用地图服务。【Navinfo Navigation SDK for iOS】产品提供了数据商店功能,初始化数据商店代码如下:
在controller中导入数据商店头文件
#import <iNaviCore/MBDatastoreItem.h> #import <iNaviCore/MBDataUpdateTask.h>
初始化
_dataStore = [[MBDatastore alloc] init]; _dataStore.delegate = self; [_dataStore setNeedsRefresh];
实现代理方法
获得数据源
- (void) datastoreRefreshed:(MBDatastore *)ds { NSArray *dataStoreItems = ds.root.subnodes; NSMutableArray *provinceItems = [NSMutableArray arrayWithCapacity:dataStoreItems.count]; NSMutableArray *cityItems = [NSMutableArray array]; NSMutableArray *cityDataStoreItems = [NSMutableArray array]; for (MBDatastoreItem*provinceItem in dataStoreItems) { CTMLObj *provinceNode = [CTMLObj nodeWithOwnID:provinceItem.itemId name:provinceItem.name level:1]; [provinceItems addObject:provinceNode]; if (provinceItem.subnodes.count) { for (MBDatastoreItem* cityItem in provinceItem.subnodes) { MLNodelObj *cityNode = [MLNodelObj nodeWithParentID:provinceItem.itemId ownID:cityItem.itemId name:cityItem.name level:2 isleaf:YES isroot:NO isExpand:NO]; [cityItems addObject:cityNode]; [cityDataStoreItems addObject:cityItem]; } } else { [cityDataStoreItems addObject:provinceItems]; } provinceNode.subNodes = cityItems; } }
其他代理回调
// 开始下载 (void)datastoreDownloadingDataItemBegan:(MBDatastore *)ds itemId:(NSString *)itemId; // 下载中进度回调 (void)datastoreDownloadingDataItemProgressUpdated:(MBDatastore *)ds itemId:(NSString *)itemId withPercent:(CGFloat)percent; // 下载完成 (void)datastoreDownloadingDataItemCompleted:(MBDatastore *)ds itemId:(NSString *)itemId; // 下载失败 - (void)datastoreDownloadingDataItemFailed:(MBDatastore *) ds itemId:(NSString *)itemId withErrCode:(MBDatastoreErrCode)code; // 开始安装 (void)datastoreInstallDataItemBegan:(MBDatastore *)ds itemId:(NSString *)itemId; // 安装中进度更新回调 (void)datastoreInstallDataItemProgressUpdated:(MBDatastore *) ds itemId:(NSString *)itemId withPercent:(CGFloat)percent; // 安装完成 (void)datastoreInstallDataItemFinished:(MBDatastore *)ds itemId:(NSString *)itemId; // 安装失败 - (void)datastoreInstallDataItemFailed:(MBDatastore *)ds itemId:(NSString *)itemId withErrCode:(MBDatastoreErrCode)code; // 数据状态改变 - (void)dataItemStateChanged:(MBDatastore *)ds itemId:(NSString *)itemId;
具体实现请参照SDKDemo中MBDataStoreController。