Archive

Posts Tagged ‘offline’

Fuchs Maps

05/03/2013 43 comments

Sometime ago after I finished my tutorials for Android offline map app I spent some time adding more features to the simple app, I guess I should share the code since many of those features are expected from any map application.

The post here won’t contain detailed explanation about how each feature is implemented since each feature might require it’s own post. Anyway if you’ve been reading my previous tutorials everything here should be straightforward and easy to understand, consider the source code provided here as some sort of raw data that someone might benefit from 🙂 .

This code is built upon the offline version of the app, so it doesn’t have web tiles support and the mapView cannot be created in xml (these can be changed easily by following the previous two tutorials).

The code isn’t perfect either, it does the job though 🙂 .

Here’s the features list:

The post will contain lots of images so please be cautious :).

Read more…

Categories: Android, Maps Tags: , ,

MapApp7 : Creating MapView in XML

26/02/2013 15 comments

Hi :), welcome to the 7th part of my tutorial on how to create offline\online map app for android.

Series outline:

______________________________________

So once again it’s an unplanned tutorial and it’s about maps 😀 .

The thing is that I got a number of comments asking about how to create the mapView in XML instead of creating it in java code, what we’ll achieve here is:

  • Make the mapView creatable from XML.
  • Assign a zoom level to the mapView in XML.
  • Adding a position marker (drawable) to the mapView from XML.
  • Add ZoomControls to the layout containing the mapView in XML.

Here’s how the final result should look like:

MapApp with ZoomControls

MapApp with ZoomControls



And just a note before you continue reading: you can add the mapView in XML like any other view, one difference though is that you cannot rely on using wrap_content in the view, since there’s nothing to wrap (something like text in a button for example) but this is not end of the world, you can either using fill_parent or use 0dip with android:layout_weight, only then the mapView will play nicely with other views :).

So either use a RelativeLayout and put your mapView and other views in it, or use LinearLayout and supply weight values for your views.

So if you’re still reading this please download the source code (along with the empty database) from MapApp 6 : Web Support since I’ll be building on the code from that tutorial. Just please remember to put the database World.sqlitedb in the folder /mapapp/ on the sdcard.

The steps we will have to do are Read more…

Categories: Android, Maps, Programming Tags: , ,

MapApp6 : Web support

16/08/2012 19 comments

Hello, welcome to the 6th part of my tutorial on how to create an offline? map app without using Google™ API, okay this time it’s no longer offline :D! now the app will be able to download tiles from the internet :D!.

Series outline:

______________________________________

At first I planned on writing some basic tips about web tiles server support but then I realized that implementing web support needs some work and code organizing since multi threading becomes a must!. You cannot wait for the tiles to be downloaded in the UI thread!.

We will assume that you have a running tiles server that provides you with tiles you specify using a custom url like this:

http://myserver.com/?x=1&y=3&z=0
or

When we want a specific tile we first search if we have it in our memory cache, if we don’t then we search in the database, if we fail to find it then we download it from the internet.
It’s kind of similar to multi cache levels in a cpu, if one level fails it gets the requested data from the next level, when data found in a certain level all lower levels save a copy of the data since it’s highly likely to be asked for the same data in the near future.
In our case when you don’t have a tile in memory or in database you get it from the web server and then save it in the database and keep it in memory for later use.

We’ve already implemented the first two levels (Memory & database) in the tutorial part 4, the TilesProvider class covered them both. but we didn’t have any threading manipulation, this time we have to be very careful about threading stuff. We will implement new classes and modify some of the old ones, the changed lines in existing classes will be highlighted in grey. Also note that if you’re using Eclipse as your IDE you can always count on the keyboard shortcut Ctrl+Shift+O to automatically import the right packages.


We will add three source files to our project in a new package called com.mapapp.tileManagement.web

Let’s first implement the class TileDownloadTask, this class handles Read more…

Categories: Android, Maps, Programming Tags: , ,

MapApp5 : MapView and Activity

06/04/2012 64 comments

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

Series outline:

______________________________________

So up until now we didn’t see any results :(, this is where everything changes :D.

In this part we’ll write three classes:

MapView: a custom view to render and manipulate the map.

MapAppActivity: the main (and only) activity for the app, mainly creates the MapView and handles activity state changes.

MapViewLocationListener : An extended LocationListener that knows how to deal with a MapView.


MapView:

First thing you should know about this view is Read more…

Categories: Android, Maps, Programming Tags: , ,

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…

Categories: Android, Maps, Programming Tags: , ,

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: , ,