2
votes

Is there a way by which I can directly use mbtiles database with MKTileOverlay without using a third party framework like MapBox or any other?

Right now, I have the tiles stored in a folder structure and the code I am using is below:

NSString *tileDirectory = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Tiles"];
NSString *tileDirectoryURL = [NSURL fileURLWithPath:tileDirectory isDirectory:YES];
NSString *tileURL = [NSString stringWithFormat:@"%@Z{z}/{y}_{x}.png", tileDirectoryURL];
tileOverlay = [[MKTileOverlay alloc] initWithURLTemplate:tileURL];
[tileOverlay setGeometryFlipped:YES];
[mainMapView addOverlay:tileOverlay];

But now I want to have a tiles.mbtiles sqlite database instead of the files in folders.

Please suggest me how can I do this. How do I initialize the MKTileOverlay object if I choose to use sqlite database. How will I put {x},{y},{z}.

I went through the documentation of MKTileOverlay and found that :

- (void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *tileData, NSError *error))result

can be used but I am not able to understand how can I use it? If any one can please give ma a short example then it would be very helpful.

1
Hi, I have the same problem and I don't want to use mapbox. Please, any example of use mbtiles without it? In my case, OSMMapKit is not working...Thank you!Eusthace
@Eusthace. I was not able to use mbtiles database directly. I had to store the PNGs in the bundle and reference them with the code above in order to render them. But, this was almost a couple years back. Hopefully, there are options available now to do that. I know for a fact that Android can use mbtile database to render the tiles without the use of a third-party library. Also, in the code above, the geometry flipped property must be set to NO in order for it to work.Kunal Shrivastava
Thank you for your help. Yes, but in my case, I don't know why I can't get to work my tiles from maptiler. Do you have a work example? Thank you anyway!Eusthace
@eusthace Did you find way to display tiles from database?Hardik

1 Answers

0
votes

You could take a look at how this project does it…

https://github.com/t2wu/OSMMapKit

It doesn't seem to be finished yet but it should get you on the right path.