How to use OSM map in an android application.? Is there any tutorial to learn about using OSM in android.?

I don't know of any tutorials but here's the code I wrote for a minimal example using Osmdroid.

// This is all you need to display an OSM map using osmdroid
package osmdemo.demo;

import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import android.app.Activity;
import android.os.Bundle;

public class OsmdroidDemoMap extends Activity {
    private MapView         mMapView;
    private MapController   mMapController;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.osm_main);
        mMapView = (MapView) findViewById(R.id.mapview);
        mMapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
        mMapView.setBuiltInZoomControls(true);
        mMapController = (MapController) mMapView.getController();
        mMapController.setZoom(13);
        GeoPoint gPt = new GeoPoint(51500000, -150000);
        mMapController.setCenter(gPt);
    }
}
/* HAVE THIS AS YOUR osm_main.xml
---------------------------------------------------------- XML START
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <org.osmdroid.views.MapView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true" />
</LinearLayout>
---------------------------------------------------------- XML END
Include slf4j-android-1.5.8.jar and osmdroid-android-4.1.jar in the build path
(Google search for where to get them from)
*/

Note that you must now use the latest version (4.1) to avoid getting blocked from downloading tiles from OSM.

Also note that they are moving their repositries to Github and the process isn't complete yet. This page downloads holds the links for the jars


This OSMdroid sample project is definitely the simplest that i have come across. No more than 5 minutes to be up and running. Pay attention to the manifest file.

For a bit more complexity, this tutorial displays a map with a current geopoint.

Here are some snippets from various projects. Haven't tested all of them, though.

You should download OSMdroid and SLF4J, place in libs folder, Add as Library osmdroid, fix AndroidManifest.xml with proper permissions (see first tutorial). If you do this, there is no need to alter gradle.build file as recommended in first tutorial.

I recommend that you use, for starters, the older versions of osmdroid (3.x) when using these. Once you are comfortable, migrate to newer version of osmdroid (4.x or 5.x).

GeoPoint and MapController classes change names in newer versions, so watch out for INCOMPATIBLE TYPES ERROR

IGeoPoint cannot be converted to GeoPoint

IMapController cannot be converted to MapController


I have explained the steps HERE. I also recommend you take a look at their Sample Project which is very useful. And their documentation about HOW ;)

And for Offline Use

1- you must download the map using MOBAC.

2- Place it into /mnt/sdcard/osmdroid/

After these steps everything is the same as @Nick explained.