简体   繁体   中英

Using offline database in Route-Me

I'm trying to use an offline MBTiles database using Route-Me . To accomplish this, I'm using Landez , which in turn depends on 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.

Here's the code I use to make the mapView and load the database:

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; even if I delete the database entirely, I get the same log output. IOW, the problem is probably as a result of Route-Me being unable to find the file. Any help would be appreciated!

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

I was having some issues with sqlite db's generated by map2sqlite until I changed the line:

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. I think it might have to to do with mbtiles tiling order vs osm's tiling order.

-- 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.

The line Randy highlighted

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.

And I was having the exact same issue, make the changes that Randy suggested above and it works.

ultimately however I wrote a php script to rename the filenames of the tiles to be correct. 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.

I made your change above but then had some problems centering the 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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