Archive

Archive for March, 2012

MapApp4 : TilesProvider

23/03/2012 3 comments

Welcome to the fourth part of my tutorial on how to create a map app for Android without using Google™ APIs :).

Series outline:

______________________________________

So now we have a TilesManager to do all the math for us & provide us with tile indices, we still need something to give us the actual images of the tiles, this is what TilesProvider does each time our MapView asks for tiles images the TilesProvider will load the data from the Database then return them to the MapView.

Each time we need to get our tiles images we fetch the data from the map database and convert the data into a Bitmap that can be rendered in our MapView, querying the database is relatively a slow operation, to make it worse, building a Bitmap also needs some time, so we must implement some sort of optimization, I’m leaving the database part and focusing on the Bitmap creation.

Instead of recreating a new Bitmap each time we check to see if Read more…

Advertisements
Categories: Android, Maps, Programming Tags: , ,

MapApp3 : Writing a tiles manager

19/03/2012 15 comments

Welcome to the third part of my tutorial on how to create a map app for Android from scratch and –>without<– using Google™ APIs :P.

Series outline:

______________________________________

Okay, as I said earlier the TilesManager will provide us with calculations needed to get the right tiles and render them in the right place.

TilesManager will have some state variables: position in degrees (longitude & latitude) plus a zoom level.

Using these state variables the TilesManager should be able to provide us with a rectangle (left, top, right, bottom) that contains the indices for the tiles, for example if the rectangle was like (0,3,2,5) it means we should fetch any tile that satisfies:

0 \le xIndex\le 2 \& 3 \le yIndex \le 5 \& zIndex=zoom

where zoom is the zoom level stored in the tile manager.

First we need to write a helper class, PointD is just a double Point which Read more…

Categories: Android, Maps, Programming

MapApp2 : App Design

10/03/2012 4 comments

Welcome to the third part of my tutorial on how to create a map app for Android without using Google™ APIs :).

Series outline:

______________________________________

Okay, I’m supposed to show you a class diagram here but I changed my mind, since the app is simple I’ll explain each class in some lines :).

TilesManager: this class contains all the calculations needed to power our app, as I mentioned before maps are made up of tiles, we need to know exactly what tiles to fetch, we also need to convert latitude and longitude to pixel coordinates to display markers, this class by itself doesn’t contain the tiles, it just provides us with methods to Read more…

Categories: Android, Maps, Programming Tags: , ,

MapApp1 : Theory you need to know

09/03/2012 4 comments

Welcome to the second part of my tutorial on how to create a map app for Android without using Google™ APIs :).

Series outline:

______________________________________

In this part I’ll give simple information about maps and some terms and how they are used, hopefully saving you some time of searching.

Since I’m not a geography expert, please note that some information here might not be accurate, corrections are welcome 🙂 after all I’m just a programmer who learned what he needs to accomplish his goal.

I’ll provide additional links for further reading at the end of this post.

Earth shape : although the earth isn’t a perfect sphere, some map systems treat it as a sphere, I guess that’s okay for everyday use.

Map projection : from Wikipedia: “A map projection is any method of representing the surface of a sphere or other three-dimensional body on a plane. Map projections are necessary for creating maps. All map projections distort the surface in some fashion. Depending on the purpose of the map, some distortions are Read more…

Categories: Android, Maps, Programming Tags: , ,

Building an offline map app for Android

09/03/2012 182 comments

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:

  1. 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).
  2. User can touch control the map (Panning), zoom in\out using volume keys.
  3. 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 )

MapApp Screenshot

A screenshot from the emulator
(I’m not really in Madagascar, just picked a random point :P)

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).
Read more…

Categories: Android, Programming Tags: , ,