Building an offline map app for Android
Hello there :), this tutorial series is about building a very simple map application for Android from scratch and without using Google™ APIs
(Don’t get frightened by the scroll bar of your browser 😀 the comments made this post look long 😀 )
The main app features will be:
- Displaying a map stored in a database on the SDcard, in other words : offline* map, no internet connection is required (but easy to implement online functionality).
- User can touch control the map (Panning), zoom in\out using volume keys.
- A marker will be displayed on the map depending on the user’s GPS position.
*Update 16/8/2012: online maps are now supported in tutorial part 6
as mentioned before : we’re not going to use Google™ APIs.
As you can see the app will be simple, other more complex functions can be added later.
Q: Why not use Google™ maps APIs (eg: MapActivity)?
A: it requires a working internet connection.
A: you might want to write your own classes.
A: you might want to know how things work.
Q: Aren’t there free map apps on the Android Market?
A: Yes there are and they are really good ones, Locus Free, RMaps, Orux Maps, these apps can run with both online and offline modes, I mainly use Locus Free, but I like writing my own apps and learn new things.
before starting this tutorial I’ll show you the final result, so that you can decide whether to continue reading or not
The app and the tutorials target API Level 7 as a minimum SDK (That’s Android 2.1 )
Here’s the source code (Eclipse Project) and the apk file, after you install it on your device\emulator, copy this map file world.sqlitedb to your /sdcard/mapapp/ (You’ll need to make the folder yourself).
Okay, Start the GPS and run the app, A red marker will be displayed to pinpoint your location when a GPS fix is available.
- Use volume keys to zoom in\out.
- Drag the map with your finger.
- M\Menu to simulate being in Madagascar.
- H\Camera focus button to center the marker in screen.
This map was downloaded from OpenStreetMap servers with only 4 levels of zoom, zooming more will only display a gray background with no map visible, the reason for this is the map file not the app itself, you can use a different map file or internet map source with more zoom levels (more on that later).
This app can be a skeleton for more exciting apps, once you’ve done this simple app you can add features like:
- Add a tracking feature which allows you to save and view your path on a map, it’s very simple once you have finished writing a class capable of rendering a map.
- Extract location data from photos to display thumbnails of the photos on a map, this way you can see where did you take your photos, there’s actually a cool app for Windows Phone 7 that does that, it’s called Where Did I Take That.
- Add proximity alerts, you might want to be notified when you get close to some places.
- Any other idea that requires a map :).
Although these tutorials are about creating an offline maps app, I’ll give some hints on how to easily make it work with online map services, with the proper app design it will be easy to switch between two modes.
After reading all this, I hope that I got your attention and you’re interested in this tutorial, if not it’s okay with me 🙂
I’ll try to keep each tutorial as short as possible.
- Series aim. (What you have been reading now :))
- Theory you need to know. (Basic knowledge you need before starting)
- App design. (Class diagram and some explanation)
- Writing a TilesManager. (Will provide calculations functionality)
- Writing a TilesProvider. (Will provide us with map images)
- Seeing results with MapView. (A custom View that displays a map)
- Adding web support. (Adding support for online maps)
- Creating MapView in XML (Supporting XML layout files)
- Extra: Fuchs Maps (More features and functionality)
Each tutorial title will start with the prefix “MapApp” :).
I really hope you’re still reading this :D…