Saturday, 11 August 2012

Maps on mobile devices - current status

Standard web maps

As I mentioned in my post on the mobile version of my maps back in January, there are two major issues with using standard web maps on mobile devices: online connection, and battery (well, all right, there's a third issue: whether you can actually read the maps in direct sunlight). These are linked: the longer you maintain a connection, whether by wifi or through a mobile network, the quicker the battery will go flat. No doubt batteries will improve, and their life between charges lengthen, but at the moment you are unlikely to be able to use them with the network connection on for longer than a couple of hours. As I said, a possible strategy is to just maintain the connection long enough to display the map for your next stage, then turn it off and only turn it on again when you move out of that area. However, if you are out in the wilds somewhere you may not be in signal range.


So it would be better if you could save the maps on your mobile device so you can download what you need when you have a connection, and then use this saved version without the online connection. This is essentially what you do with a GPS device, which doesn't have an online connection.

To some extent, you can do this 'caching' with existing web maps, such as mine. At the moment, map servers generally serve rectangular images ('tiles' in the jargon) of say 256x256 pixels, georeferenced so it's clear which piece of the earth they represent and hence at what scale (zoom level). The browser software then requests however many of these images it needs for the current browser window, and displays them in the correct position; any feature/vector data for points and routes, for example from a gpx file, can then be rendered in the correct position on top of these images.

So, if you want to cache this, you need to save (a) the software, (b) the images, and (c) the vector data. Browsers generally have their own cache space and do this saving automatically. However, neither users nor developers have much control over this. It saves everything it reads regardless of whether the user considers it important or worth caching. Users can only clear the cache completely, and cannot say, for example, I want to clear everything from this site and not from that one. When the cache space is full, it deletes old pages, again regardless of whether the user would like to keep them. The cache is browser-specific, so if you use more than one browser, each one will save the same pages in its own cache. In addition, it can only load a page when there is a connection.

For this last problem, there is now a solution: modern browsers can now save (a), the software, in something called the appcache (though this suffers from the same problem as the normal cache in that it is browser-specific, each browser storing the same 'app' in its own appcache).

(c), the vector data, is relatively easy to handle: the user can simply save it in whatever storage the device has, and modern web browsers can then load it from there. The main problem is with (b) the images.

Storage space

There are 2 issues: firstly, the images are large, some 20-40kB apiece, so the more you save, the more space you need. Google's tiling system, for example, needs more than 350 billion tiles to cover the world at 20 zoom levels (I'll leave you to work out how long it would take to download the lot). Browsers do have the ability to store a certain amount of data in another type of storage called localStorage; this is however limited in size, and unlikely to be much more than those necessary for a day or two's walk at one zoom level. So it offers little advantage over the normal browser cache, other than that developers (and to some extent users) can control what is stored and what isn't.

There are (native) apps available which will cache the tiles for you as you fetch them over the internet. Because they are run directly by the operating system and not in the browser, they are not subject to browser caching limits and can use any spare storage available in the device. However, this is not limitless (not even a fraction of Google's 350 billion tiles), so again if you are on a long trip and need maps to cover a lot of ground and/or at different zoom levels, you will have to delete the tiles regularly to make space for new ones.


They are also subject to the second issue: copyright. Almost all decent mapping costs money to create and keep up-to-date, so is subject to copyright. Although copyright generally permits small amounts of copying for personal use, the legality of large amounts of caching is dubious. Most commercial providers, such as Google, Bing, and the APIs from the Ordnance Survey and the French IGN, explicitly forbid it. Many mapping agencies supply datasets for use with GPS devices, and some of these are also available for mobile apps (for example, the ViewRanger app), but unlike the maps on say my website, you have to pay for that, maybe even more than you would pay for internet access (though probably less than you would pay for paper maps).

Vector mapping

Mapping agencies maintain their maps in vector format (i.e. the definition of what will appear in the images, not the actual images themselves). Back in the early days of web maps, servers were powerful things and client devices like PCs feeble, so the best way to serve the map data was to 'render' it on the server as images which client browsers could easily display. Nowadays, even mobile phones are pretty powerful, so are better able to render the data themselves. Also, vector data is way smaller in size, so is faster to transmit and takes up less room when cached. For this reason, web maps are beginning to be supplied as vectors, leaving the client to convert this into the map image. The first major player to do this was Google: Google Maps for Android now sends its maps not as images but as vectors, meaning the transmission bandwidth and storage needed for caching are much less. Apple is planning a similar change in its new mapping app for iOS 6, promised for later this year. It remains to be seen whether the national mapping agencies do likewise for their map data.


One major exception to the copyright issue is OpenStreetMap. Although they do maintain tiled images similar to Google et al, their map data is freely available in vector form and can be downloaded on a country or region basis to your mobile device. Although these files are much smaller than the equivalent image files would be, they are still many megabytes in size, so are best downloaded in a compressed format (using the cheapest internet connection you have available). AFAIA, there is not yet any browser software for reading this compressed data, but various native apps are now appearing which can read these vector files, and display them along with any vector data from gpx or kml files; one example I have used on Android is OsmAnd. It looks like at present there is no standard format for this compression, and different apps use different incompatible ones. I would hope this situation will improve. And different apps also supply different data; OsmAnd for example supplies separate contour data which is a significant improvement for use in hilly countryside. Although OSM is improving rapidly, outside major towns it remains of limited use; proper topographical maps from the national/regional agencies are generally far superior for country walks.


In towns, my preferred solution is to use an app that can read OSM vector data; download this data before your journey and then use the app offline. For the countryside, OSM maps are not very detailed, so my preferred solution is to use the maps from national mapping agencies with my mobile map pages with or without the caching option.

For those countries where these map pages are not available, such as Switzerland, there may be an app for your device licensed to cache their tile images for use offline.

For the future, it's a pretty safe bet that things will have changed considerably in 2 or 3 years time.

Friday, 16 March 2012

VML now deprecated on map pages

Only applies to users of Internet Explorer versions older than 9.

Most modern browsers use Scalable Vector Graphics for rendering map data. For many years Microsoft refused to implement this, and used its own renderer, VML, in IE. This meant special code to deal with VML had to be included in map pages to cater for users of IE. Microsoft finally changed this policy and included SVG in IE9. They have now deprecated VML, and it will no longer be included in IE10.

So that users of browsers that support SVG are not slowed down loading unnecessary code, I have now removed VML support from the standard pages. It will be loaded separately for users of IE < 9.

As SVG rendering is much faster than VML anyway, users of IE < 9 are strongly recommended to either upgrade to version 9 or use another browser such as Chrome or Firefox.

Thursday, 5 January 2012

Mobile map pages waiting to be tested

Although my mapping pages have been usable on mobile phones for a while, they've not been very mobile-friendly. I have now written more mobile-friendly versions:
* simple map display pages can be reached from:
* using geolocation (GPS) to display your current position on a map:

Advantage of using a phone for this sort of map display is you can do a lot of other things with a phone which you can't with a dedicated GPS device. Disadvantage is you need access to both internet (which may be a problem in remote areas) and GPS satellite signal; having these on for any length of time soon chews up battery power.

An alternative strategy to preserve battery when your position changes only slowly (for example, when on foot) is to turn on internet access and GPS at or before you start, go to your position on the map, then turn off both internet connection and GPS and only turn them on when you need to refresh your GPS position or you need to pan the maps. Once you have the page in your browser, the map display will stay in the browser cache, so you could also pan the map over your full journey at or before you start, which will cache those map tiles you need later; this strategy won't however work for the routes option, as the route lines are not cached.

Alternatively, you can get the maps while you have internet access, and use screen capture to save a snapshot of the map, which you can then use in the field leaving internet access off. However, these snapshots are not georeferenced, so you can't use GPS with them.

Feedback welcome in comments below. Please state which device and browser you are using.