Thursday, July 4, 2013

Offline Maps on Android - Leaflet.js+SQLite+MBTiles

Offline Mapping Bliss...


The stealth project that Kaidad is working on requires offline maps. I had very good experiences with PhoneGap at my day job, and since I'm in the prototype phase, this seemed like a good place to start. I also have the limitation that at the moment I do not own an iOS device - only Android. After spending some time researching offline maps for Android as well as various mapping libraries, I came across this post by Geospatial Scott: Phonegap + Leaflet + TileMill = Offline Mobile Maps. This demo used a SQLite PhoneGap Plugin for iOS, which presented a little problem since I needed this to run on my Android phone. A few sleepless nights and early mornings later, and I finally saw the above map.

Overall, I'm quite pleased with the proof of concept, and will build on this idea. However, I would really like to see better performance when panning and zooming. There's a noticeable delay in rendering the tiles that really surprised me since it's loading from a local database rather than downloading tiles from the internet. It seems to be quite a bit slower than, say, Google Maps. I did improve performance by modifying the SQLite Plugin to use a simple StringBuilder to build the output string rather than relying on the JSONArray.toString() method which I determined to be a bottleneck after spending some quality time with traceview.

You can download the code for this demo from my GitHub account: Offline Map Demo

1 comment:

  1. Hello, I have a question, how did you resolve the problem with the blobs in SQLITE in android? I don't see the way. Thanks

    ReplyDelete