在Route-Me中使用脱机数据库

时间:2011-07-05 23:57:52

标签: iphone objective-c route-me

我正在尝试使用Route-Me使用脱机MBTiles数据库。为实现这一目标,我使用的是Landez,而后者又取决于MBUtil

现在,我得到的只是一个灰色的屏幕,其针脚位于正确的位置。这是打印到控制台的内容:

initializing memory cache <RMMemoryCache: 0x4e42e50> with capacity 32
Opening database at /Users/chrislong/Library/Application Support/iPhone Simulator/4.3.2/Applications/E53BC885-1B02-4B06-B45B-408EB9A147DE/Documents/MapOpenStreetMap.sqlite
Map contents initialised. view: MapView at 0,0-320,411 tileSource <RMCachedTileSource: 0x4e428b0> renderer <RMCoreAnimationRenderer: 0x4e13dc0>
initializing memory cache <RMMemoryCache: 0x5929930> with capacity 32
Opening database at /Users/chrislong/Library/Application Support/iPhone Simulator/4.3.2/Applications/E53BC885-1B02-4B06-B45B-408EB9A147DE/Documents/MapMBTilestiles.mbtiles.sqlite
Warning: I could not find the column named 'tile_data'.
Warning: I could not find the column named 'tile_data'.
Warning: I could not find the column named 'tile_data'.
Warning: I could not find the column named 'tile_data'.
Map contents initialised. view: MapView at 0,0-320,411 tileSource <RMCachedTileSource: 0x592a400> renderer <RMCoreAnimationRenderer: 0x5925770>

值得注意的是,该文件名为tiles.mbtiles,而不是MapMBTilestiles.mbtiles.sqlite,并存储在捆绑包的根目录中,而不是Documents文件夹。

这是我用来制作mapView并加载数据库的代码:

CLLocationCoordinate2D center = {50, 50};
self.mapView = [[[RMMapView alloc] initWithFrame:self.view.frame] autorelease];
self.mapView.backgroundColor = [UIColor blackColor];
self.mapView.delegate = self;

NSURL *tilePath = [[NSBundle mainBundle] URLForResource:@"tiles" withExtension:@"mbtiles"];
RMMBTilesTileSource *tiles = [[[RMMBTilesTileSource alloc] initWithTileSetURL:tilePath] autorelease];
[self.mapView.contents removeAllCachedImages];
self.mapView.contents = [[[RMMapContents alloc] initWithView:self.mapView tilesource:tiles centerLatLon:center zoomLevel:0.0 maxZoomLevel:[tiles maxZoom] minZoomLevel:[tiles minZoom] backgroundImage:nil] autorelease];
[self addMarkers];

Route-Me显然根本没有读取文件;即使我完全删除数据库,我也得到相同的日志输出。 IOW,问题可能是由于Route-Me无法找到该文件。任何帮助将不胜感激!

3 个答案:

答案 0 :(得分:4)

签出 - (RMTileImage *)tileImage:(RMTile)tile from MapView-&gt; Map-&gt; Tile Source

我遇到了map2sqlite生成的sqlite db的一些问题,直到我更改了这行:

NSInteger y    = pow(2, zoom) - tile.y - 1;

为:

NSInteger y    = tile.y;

我现在正在使用tilemill生成的db,所以我还没有进一步挖掘它,但是如果我是你,我会在一些调试语句中进行调查,看看它寻找什么样的瓷砖以及瓷砖的布局你的数据库是。我认为它可能与mbtiles平铺顺序与osm的平铺顺序有关。

- 兰迪

答案 1 :(得分:3)

我昨天真的在解决这个问题。

似乎有两种不同的磁贴格式,即openstreetmap使用的google xyz和TMS。

Randy突出显示

NSInteger y    = pow(2, zoom) - tile.y - 1;

将一个转换为另一个。例如,我使用Maperative构建我的地图,然后将其导出到目录中的tile,最后使用mb-util生成tiles.mbtiles文件。

我遇到了完全相同的问题,做出兰迪上面提出的修改并且有效。

最终我写了一个php脚本来重命名tile的文件名是正确的。老实说,我仍然不知道哪些软件以什么格式导出。我认为mbtiles应该是TMS,这意味着route-me是xyz,但我可能错了。

答案 2 :(得分:0)

我在上面进行了更改,但后来在地图上出现了一些问题。经过一段时间的工作后,我将上面提到的行更改为:

NSInteger y = tile.y - (pow(4, ((zoom / 2) - 1)));

希望这可以帮助任何有困难的人。