更新时间:2026/03/23 17:27
使用离线地图
使用离线地图,可满足在无网络环境下查看地图信息的需求,在有离线地图的情况下,地图SDK会优先加载离线地图。
离线地图的基本使用方法如下:
1、初始化离线地图管理类
PHP
// 创建离线地图管理类 OfflineController _offlineController = OfflineController(); // 离线地图管理类初始化 _offlineController.init(); // 离线地图管理类注册回调 _offlineController.onGetOfflineMapStateBack( callback: _onGetOfflineMapStateBack); // 下载回调 void _onGetOfflineMapStateBack(int state, int cityID) { switch (state) { case OfflineController.TYPE_DOWNLOAD_UPDATE: _setUpdateInfo(cityID); // 处理下载进度更新提示 break;
case OfflineController.TYPE_NEW_OFFLINE: // 有新离线地图安装 break;
case OfflineController.TYPE_VER_UPDATE: // 版本更新提示 // MKOLUpdateElement e = mOffline.getUpdateInfo(state); break;
default: break; } }2、获取批量城市列表
a、获取热门城市列表
PHP
List<BMFOfflineCityRecord> cityList = await _offlineController?.getHotCityList();b、获取全国城市列表
PHP
List<BMFOfflineCityRecord> cityList = await _offlineController?.getOfflineCityList();3、开始下载
PHP
await _offlineController?.startOfflineMap(int.parse(_cityID));4、下载状态
PHP
List<BMFUpdateElement> update = await _offlineController?.getAllUpdateInfo();5、暂停下载
PHP
await _offlineController?.pauseOfflineMap(int.parse(_cityID));6、删除下载
PHP
await _offlineController?.removeOfflineMap(int.parse(_cityID));7、更新下载
PHP
await _offlineController?updateOfflineMap(int.parse(_cityID));以上介绍了离线地图的基本用法,您在开发过程中如有问题可以参考官方demo。
本篇文章对您是否有帮助?