简体   繁体   English

在 Route-Me 中使用离线数据库

[英]Using offline database in Route-Me

I'm trying to use an offline MBTiles database using Route-Me .我正在尝试使用Route-Me使用离线 MBTiles 数据库。 To accomplish this, I'm using Landez , which in turn depends on MBUtil .为此,我使用了 Landez ,而这又依赖于MBUtil

Right now, all I get is a gray screen with the pins in their proper locations.现在,我得到的只是一个灰色的屏幕,其中的引脚位于正确的位置。 Here's what gets printed to the console:以下是打印到控制台的内容:

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>

It's worth noting that the file is named tiles.mbtiles , not MapMBTilestiles.mbtiles.sqlite , and is stored in the root of the bundle, not the Documents folder.值得注意的是,该文件名为tiles.mbtiles ,而不是MapMBTilestiles.mbtiles.sqlite ,并且存储在包的根目录中,而不是Documents文件夹中。

Here's the code I use to make the mapView and load the database:这是我用来制作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 is obviously not reading the file at all; Route-Me 显然根本没有读取文件; even if I delete the database entirely, I get the same log output.即使我完全删除数据库,我也会得到相同的日志 output。 IOW, the problem is probably as a result of Route-Me being unable to find the file. IOW,问题可能是由于 Route-Me 无法找到该文件。 Any help would be appreciated!任何帮助,将不胜感激!

Check out - (RMTileImage *)tileImage:(RMTile)tile from MapView->Map->Tile Source签出 - (RMTileImage *)tileImage:(RMTile)tile 来自 MapView->Map->Tile Source

I was having some issues with sqlite db's generated by map2sqlite until I changed the line:我在使用 map2sqlite 生成的 sqlite db 时遇到了一些问题,直到我更改了行:

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

to:至:

NSInteger y    = tile.y;

I'm using tilemill generated db's right now, so I haven't dug into it further, but I'd toss in some debug statements if I were you and look at what tiles its looking for vs what the tile layout in your db is.我现在正在使用 tilemill 生成的数据库,所以我没有进一步研究它,但如果我是你,我会扔进一些调试语句,看看它在寻找什么瓷砖与你的数据库中的瓷砖布局是什么. I think it might have to to do with mbtiles tiling order vs osm's tiling order.我认为这可能与 mbtiles 平铺顺序与 osm 的平铺顺序有关。

-- Randy ——兰迪

I actually wrestled with this very problem yesterday.我昨天实际上与这个问题搏斗。

There seem to be two different tile formats out there, google xyz and TMS which is used by openstreetmap.那里似乎有两种不同的图块格式,google xyz 和 Openstreetmap 使用的 TMS。

The line Randy highlighted Randy 突出显示的线条

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

Is converting one to the other.正在将一个转换为另一个。 So for example I am building my map using Maperative, then exporting it to tiles in a directory and finally using mb-util to generate the tiles.mbtiles file.例如,我正在使用 Maperative 构建我的 map,然后将其导出到目录中的图块,最后使用 mb-util 生成tiles.mbtiles 文件。

And I was having the exact same issue, make the changes that Randy suggested above and it works.而且我遇到了完全相同的问题,进行上面 Randy 建议的更改并且它有效。

ultimately however I wrote a php script to rename the filenames of the tiles to be correct.但是最终我写了一个 php 脚本来重命名瓷砖的文件名是正确的。 I'll be honest I still haven't quite got my head around which pieces of software are exporting in what format.老实说,我还没有完全弄清楚哪些软件以什么格式导出。 I think mbtiles is supposed to be TMS which implies that route-me is xyz, but I could be wrong on that.我认为 mbtiles 应该是 TMS,这意味着 route-me 是 xyz,但我可能错了。

I made your change above but then had some problems centering the map.我在上面进行了更改,但在将 map 居中时遇到了一些问题。 After working on it for quite some time I change the line you mention above to this:经过一段时间的工作后,我将您上面提到的行更改为:

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

Hope this helps anyone also having trouble.希望这可以帮助任何有麻烦的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM