Weekend Project: Pre-Loading Maps for Open Source Navigation Apps

167

Map-based navigation: it’s one of the killer apps for any mobile platform. The only sticking point is getting the maps. Downloading map tiles on the fly is the default solution for most navigation apps, but pre-loading makes more sense when it’s possible. Unfortunately, open source navigation apps have earned a reputation for clunky and awkward map-loading interfaces. This weekend, let’s look at a simpler method, so you can get on the road quicker.

A Historical Expedition

Sure, whenever you have solid data coverage and a cheap-but-fast mobile plan, you can stream maps on-demand — but even then your download speed can to a crawl at just the wrong moment. Plus, you can forget about streaming maps if you’re traveling to the back woods or headed overseas with a pre-paid SIM. Pre-loading map sets bypasses the entire problem, plus for many apps it allows you to calculate routes while offline as well.

The problem is that the open source apps make pre-loading into a colossal pain. Some provide a pre-loading interface that falls flat — such as by requiring you to manually enter unformatted latitude and longitude coordinates for the corner points, by not allowing you to see which maps it already has stored, or by attempting to download every zoom level in the database. Others simply have no pre-loading interface at all, requiring manual configuration file editing to point the app towards the right storage directory.

If you had unlimited disk space, you could always grab the entire OpenStreetMap global data set, but for all practical purposes the way most people will operate is to keep a small set of maps on their device at any one time — home, the destination city for a particular trip, and so forth.

Complicating matters slightly is the fact that different navigation apps utilize different map sources. If you’re hiking cross-country, you probably want a topographic map, so OSM’s street map source isn’t going to be any good, regardless of how easy it is to partition off the relevant boundary lines and download tiles. If you use more than one app then typically you double the amount of work involved, since most navigation apps have their own package format and directory structure — even when dealing with the same map source.

Atlas Time

We can simplify the process by using the Java application Mobile Atlas Creator (or MOBAC for short). MOBAC includes a web map renderer on which you can select the region of which you’re interested in generating an offline map source, plus controls that let you configure zoom level and other options. Whenever you have your “atlas” (which is MOBAC’s term for each individual offline map bundle) configured, you can have MOBAC batch-download the tiles and properly configure them for the navigation device of your choice.

You can download MOBAC from the project’s site on SourceForge.net. For most users, all you will need to do is grab the .jar package linked to under “Download” on the home page. It requires Java 1.6 or newer, which is standard fare for Linux. The developer recommends you also download the latest build of Java Advanced Imaging from Sun (or presumably, Oracle), although this is optional. A subset of mapping applications also require the Sqlite database; the Download section links to the appropriate Java library.

The current release of MOBAC is version 1.9 beta 5, which officially supports 28 different navigation and mapping apps. There are others that use a compatible format, but don’t make the main list. Most are turn-by-turn mobile navigation aids like AndNav, OsmAnd, and Osmdroid, but off-road utilities like Mobile Trail Exporer, specialty apps like Nokia Sports Tracker, and GPS-logging apps are supported as well — including those for dedicated GPS hardware like Magellan and Garmin units.

MOBAC Usage

After you’ve downloaded the requisite files, cd into the resulting directory and launch MOBAC with ./start.sh &. The left-hand window pane holds a series of expandable settings docks; click on the arrow in each dock’s title bar to see its content. The right-hand pane is for GPX data, which is a different enough use case that we don’t have time to discuss it. In the center is the map view widget.

The atlas-building process is a bit quirky, but you will soon get the hang of it. The “Map source” selection dock on the left lets you choose which map is displayed in the map view. “Atlas Content” further down displays the map components you have selected so far. By default, MOBAC starts a new atlas project named “Unnamed atlas” at startup. You can work on more than one at a time — use the “New” button to create one. Just keep an eye on which atlas project is selected as you work: every time you make a selection on the map view, you can click the “Add selection” button to add it to the currently chosen atlas project.

In the map view widget, the right mouse button acts as a “grab” controller, with which you can pan and scroll the map view. The left mouse button allows you to draw a selection rectangle onto the map. The scroll wheel zooms in and out. When you have selected the region you want to save, go to the “Zoom Levels” dock and check which levels you want to download. There is some trial-and-error involved, but if you’re new you can learn a lot by visiting OSM’s web renderer and watching the zoom level there. You probably don’t need more than two or three levels; it simply depends on the detail level you want.

What makes MOBAC exceptionally useful, however, is that you don’t have to stop at one selection rectangle or one map source. You can add multiple cities (at a high zoom level) and a large swatch of highway (at a lower zoom level) all to one atlas. You can also grab OSM street data and OSM public transport or hiking maps, and merge them all into a single atlas.

When you have all of your selections made, choose “Convert atlas format” from the “Atlas” menu. This dialog lets you select the output format of your maps. The README file (which is also accessible through the Help menu) describes which format is required for each of the supported apps. For other apps, you need to look online for documentation (Mappero, for example, uses the “OSMTracker tile storage” format, which seems to be popular among the open source apps, although AndNav has its own). If you installed the Java Advanced Imaging package mentioned earlier, you can select some custom tile processing options (such as reducing the color data to save space), but it’s not required. When you’re ready, click “Create atlas” and MOBAC will download all of the tiles in your atlas selections, convert them, and package them for use on your device.

At this point, all that remains is to copy your freshly-minted atlas to your mobile device. Here the process varies from app to app. Start by clicking the “Open Atlas Folder” button in MOBAC’s “success” dialog. Each atlas project you’ve built will be saved in one location, so you can maintain a local library. Whether you can simply drag-and-drop an atlas folder from your hard disk to a USB-attached device, or whether you need to navigate inside it and drag the sub-folders independently depends on the app. Start by consulting the README file; if you don’t find instructions there, go to the MOBAC wiki, which maintains pages on the subject — often linked to real-world how-to guides.

Radio Free Data

You may have noticed that there is a long list of map sources rambling down the sidebar of the MOBAC homepage, but that I have only discussed using OSM-based data sets. That is because Robert, MOBAC’s lead developer, recently made a change to the application that disabled most of the commercial and proprietary map sources. As he explains on the forum, he did not do this because the map data was licensed in a manner incompatible with MOBAC’s GPLv2 , but because the terms of use for a handful of the more litigious map providers explicitly forbid so-called “bulk” downloads through their APIs.

Whether your personal usage of MOBAC constitutes a “bulk” request depends on how much you select, but Robert did not feel like working it all out individually. Instead, he disabled the problematic services, and now says he will re-enable any of them for which a clearly-expressed deal can be reached. He is asking MOBAC users to contact map service providers rather than doing the deal-making himself.

I have grave doubts as to whether that third-party negotiation technique will work, but in the meantime I don’t mind: OSM works everywhere I have traveled, and it is explicitly free. You can read more about the map source setup process in the same thread, including how to add map sources that are free but don’t offer any TOS at all (or simply don’t respond to inquiries). It’s important to notice, however, that a web map source has to meet some technical requirements in order to function. The MOBAC site has a list of map sources that are incompatible, and a tool to help you determine if a new source meets the requirements.

Westward Ho!

It only takes a few seconds for MOBAC to download and convert hefty map collections if you have a reasonably fast Internet connection. Doing so once might be a slight convenience when compared to making a single custom map set, but what makes MOBAC worth keeping around is how it simplifies the process on a repeating basis.

As mentioned above, you can save your old atlases for later re-use; MOBAC can also be configured to freshen already-downloaded tiles so that updates to the map are added to your existing atlas. It also allows you to bookmark map views, so that you can quickly re-visit settings; this is especially useful as you are getting used to what your preferred zoom levels are for different types of transport. In addition, MOBAC excels because of its support for multiple map layers. How uninteresting would it be if you had to choose between street maps or public transport, but not both?

Open source navigation apps have come a long way in a short period of time, particularly on Android, but they all still have room to improve in the area of offline map support. It is an understandable afterthought if you are the developer, where offline and online maps are such very different features. Which is why it’s such a good thing MOBAC is available to bridge the gap.