3

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!

Chris Long
  • 3,007
  • 4
  • 30
  • 37
  • can you send me reference of how you add you tiles images to route me cause i am stucked with this issue now i have the map image and i managed to add to trim it to tiles but how i can add it to the map.. Thanks – Mina Nabil Jan 21 '12 at 13:36

3 Answers3

4

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

rcarver
  • 963
  • 9
  • 13
  • Wow! Your patch worked! The whole map displays properly now! Thank you so much! If you want, you should log into GitHub (or sign up if you haven't already), and fork [the file](https://github.com/route-me/route-me/blob/master/MapView/Map/RMMBTilesTileSource.m) and submit a pull request so this won't be a problem for anyone else! Thanks again! :D – Chris Long Jul 10 '11 at 02:42
  • The similar issue was [fixed by Sergej Tatarincev on Landez](https://github.com/makinacorpus/landez/commit/fb0b77deddf469bfdd72e9a9d65fa04a56f1b5e1) – leplatrem Jan 06 '12 at 09:49
  • It did not work for me, I still get the gray view. please help – Kenan Karakecili Jul 23 '14 at 07:35
  • This was a very old patch (2011). I'm not using the main route-me fork anymore, as it doesn't seem to be getting any action (last commit was 2012). The work that tilemill is doing on their fork is much more recent and very active. Check it out: https://github.com/mapbox/mapbox-ios-sdk – rcarver Jul 24 '14 at 13:04
3

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.

Code Lღver
  • 15,573
  • 16
  • 56
  • 75
dageshi
  • 41
  • 2
  • Welcome to Stack Overflow; thank you for your input! This is a great website, so I hope you stay and contribute. It would have taken me forever to solve this on my own, *if* ever! And I know what you mean about all the applications involved in this process; it took me about three days to wrap my head around who does what and where, haha. – Chris Long Jul 10 '11 at 02:46
0

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.

Code Lღver
  • 15,573
  • 16
  • 56
  • 75
joshkendrick
  • 3,497
  • 8
  • 38
  • 52