Saturday, December 10, 2011

Offline Maps in Android Applications - Part 2

We will continue this sequence of articles about offline maps in Android, showing how we can create a disconnected set of maps, which we will show using Osmdroid API. We will start by download and install Mobile Atlas Creator, a free map visualization and atlas creation tool, which works with many different map sources like Google Maps, Yahoo Maps or Open Street Maps.

Mobile Atlas Creator interface looks like this.



















Lets define a new atlas! At the left panel, use the "Map source" list box to choose an online data source. In this example I am using Google Maps. The next step is moving the map on the right panel to select the part of the world you desire to show on your application. You can use the mouse to select a rectangular area on the map. The coordinates of this area will appear at the "Selection coordinates" on the top of the left panel (you can also, of course, input the coordinates directly on the N, W, E and S text boxes). After this, click on the check boxes named from 0 to 19 on the "Zoom Levels" option, to select the zoom levels you want to use. I recommend you try from 0 to 15 to follow this tutorial. Type some tittle (for instance, "MyMaps") for your atlas at the "Name" text box, and click the "Add selection" button. The "Atlas Content" box will be filled with the "MyMaps" atlas features you have just defined.

In order to really create your atlas, select "OSMAND tile storage" format on the "Atlas settings" section and click the "Create atlas" button. A dialog will appear, showing the progress of the download of the images and creation of the maps that will compose your atlas.


The resulting atlas will be stored at the "atlases" sub-folder of the Mobile Atlas Creator installation directory, into a new folder named with some identifier like "Unnamed atlas_2011-12-06_232235". Inside this folder you will find another folder named after your selected map source, in this case "Google Maps". Take a look inside this folder. There is a collection of numbered folders. These numbers indicate the zoom levels you have defined, and inside each zoom level folder you will find another collection of numbered folders containing the real tile images, with numbers as names and the extension .png.tile, which is the extension that Osmdroid API will recognize.

You can now set the content of the resulting atlas folder into a ZIP file, lets say "MyMaps.zip" (remember, this content will be a folder named after your online maps source). Our next post will show how to implement our offline map application using this file as its data source. See you soon!

Thursday, December 8, 2011

Offline Maps in Android Applications - Part 1

The canonical way to present maps in Android applications is using com.google.android.maps.MapView class, which has Google Maps has its unique data source. This implies that you are restrained to a single map source, and that your application  must have an available data connection and internet access privileges in order to show maps. Offline maps are not possible (at least while I write these lines).

Open Street Map provides a solid alternative to Google Maps. It was conceived following the model of Wikipedia: Content is provided by the users community. A lot of effort has been made by people around the world to provide maps which follow OSM specifications, and more content is continuously being added or updated. The success of Open Street Map has promoted the creation of several open source software projects aiming to develop alternatives to the original mapping on Android, based on Google online services (initiatives as Osmand, an open source application which offers navigation and routing functionality).

In this small series of articles we will talk about implementing maps visualization using Osmdroid API, a set of classes which substitutes (with further features) Android's standard MapView and its support classes, making possible to use a variety of map sources (including Google Maps), connected or disconnected. In our next article we will show how to generate a ZIP file containing a set of raster (PNG) maps, which we will use as a disconnected data source to our application. See you soon!