This project is based on Phonegap + Leaflet + TileMill = Offline Mobile Maps by Geospatial Scott. In my case, I don't own an iOS device, and eventually want to have versions running in both iOS and Android, so I dove into the process of building an Android version of the demo.
This version uses the Android PhoneGap SQLite Plugin by brodyspark.
- The SQLite Plugin has different method signatures and response objects than the one used by Geospatial Scott, and always operates in a transaction boundary
- The SQLite Plugin always looks for database files in the path returned from "cordova.getActivity().getDatabasePath(dbname)" whereas the file download logic used in Geospatial Scott's demo uses the file system root path. I added two methods to the SQLite plugin to help mitigate this issue: 1) getDatabasePath, and 2) databaseExists. I probably could have just used getDatabasePath to check if the file exists, but this seemed a little cleaner.
- The version of Leaflet.js I'm using is the latest (0.6), and the _loadTile and getTileUrl methods were changed from the version used by Geospatial Scott. Please note the _adjustTilePoint method in _loadTile - it's important!
- After getting the map to load, I noticed very poor performance when panning and zooming - even on my device it would take several seconds to load tiles and render the map. I spent some quality time with traceview and determined that most of the time was spent converting the JSONArray object built from the database results into a string, which seemed very odd considering the array only contained one value - the map data. It turns out the JSONArray implementation that comes with Android writes the data to the string writer one character at a time. I modified the results2string method to use a StringBuilder instead and this proved MUCH faster. I'm still not at all happy with the performance when loading, panning, or zooming. Considering the fact that the tile data is being loaded from a local SQLite database, I expected it to be nearly instant, not slower than when using web-based maps from Google Maps since there is no network latency involved. I would REALLY appreciate help with the performance!