Osmdroid 离线地图存放位置的研究和详细分析

本文详细介绍了如何在手机上通过osmdroid调用离线地图,包括地图图层的查找、离线地图的存储方式以及如何使用本地数据库存储图层信息。文章深入分析了osmdroid默认的地图加载机制,并提供了自定义地图加载流程的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载:
http://www.myexception.cn/operating-system/795478.html

在手机通过osmdroid调用离线地图必须放在sdcard目下、如果采用osmdroid调用地图,那么用户查看地图手机上面一定有一个目录叫/sdcard/osmdroid/目录。目录下存放着调用的图层。





在线地图例如路径如下:

/sdcard/osmdroid/titles/poly_landmarks/14/3667/6189.png.tile



表示osmdroid调用的图层为poly_landmarks,14为缩放大小,3667为图层的索引,3667目录下为具体的索引下图层tiles图片。



离线地图调用路径:



/mnt/sdcard/osmdroid/gmap.zip













文档说明如下:



Map tiles in Osmdroid are provided by map tile providers. The default tile provider used by Osmdroid is MapTileProviderBasic. This provider extends MapTileProviderArray, which means that it is an array of a few other tile providers - when a tile is requested these tile providers are asked one by one for a tile image until one of them provides it. Take a look at the constructor of MapTileProviderBasic:

public MapTileProviderBasic(final IRegisterReceiver pRegisterReceiver,
final INetworkAvailablityCheck aNetworkAvailablityCheck, final ITileSource pTileSource) {
super(pTileSource, pRegisterReceiver);

final TileWriter tileWriter = new TileWriter();

final MapTileFilesystemProvider fileSystemProvider = new MapTileFilesystemProvider(pRegisterReceiver, pTileSource);
mTileProviderList.add(fileSystemProvider);

final MapTileFileArchiveProvider archiveProvider = new MapTileFileArchiveProvider(pRegisterReceiver, pTileSource);
mTileProviderList.add(archiveProvider);

final MapTileDownloader downloaderProvider = new MapTileDownloader(pTileSource, tileWriter, aNetworkAvailablityCheck);
mTileProviderList.add(downloaderProvider);
}
There are three map tile providers added to the array of providers, in this order:

MapTileFilesystemProvider - provides tiles from the file system (SD card directory)
MapTileFileArchiveProvider - provides tiles from archive in file system
MapTileDownloader - provides tiles by downloading them from the Internet (e.g. from OSM servers)
So the MapTileProviderBasic looks for a given tile first in the file system, if the tile is not available then it looks for it in archive files and again if it is not available there it downloads the tile from the Internet.

Ok, this is the default mechanism. If you want to change this mechanism to look for tiles stored in a DB then you can create you own class similar to MapTileProviderBasic. So your class could also exte nd MapTileProviderArray and just use other providers in the constructor. In Osmdroid there is a class DatabaseFileArchive which could probably help you in reading tiles from the DB.

After creating your own tile provider you should use it instead of the default one. Map tile providers are attached to the MapView. Some of the constructors of MapView take MapTileProviderBase as an argument - you can use one of them to attach your own provider.





综述:osmdroid使用地图的方式如下

1.首先调用MapTileFilesystemProvider 在sd card 目录查找地图图层。

2.如果没有,调用MapTileFileArchiveProvider 查找zip类型的压缩文件。

3.如果没有,到官方下载地图。



如果想使用本地数据库存储图层信息,那么需要重设置MapTileProviderArray实现地图图层的存储。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值