Integrating MapsForge into an Android project

MapsForge is an Android library that allows you to display Offline detailed maps. Installation instructions are available on its official website, as well as good samples.  This tutorial explains how to integrate it inside your Android App once it is installed.

create a new Android project, and open it. Mine will be named “PrjOfflineMaps”. You can also use a project you already have.

Eclipse IDE

On the Package Explorer, right click on project root  > Properties

on the left list, click on “Java Build path”, and mark the “Libraries” tab.

Now click on “Add external JARs”, and point to the hidden folder where maven has installed the repo:




Haven’t tried it on Linux, but there has to be a similar folder inside your home directory.

Now click on tab “Order and Export”, and make sure “mapsforge-map-0.3.1-SNAPSHOT-jar-with-dependencies.jar” is checked.

Now create a new Activity that extends “MapActivity” (

public class MyMapActivity extends MapActivity{
    private static final File MAP_FILE = new File(Environment.getExternalStorageDirectory().getPath(), "");
     protected void onCreate(Bundle savedInstanceState) {
       MapView mapView = new MapView(this);
       FileOpenResult fileOpenResult = mapView.setMapFile(MAP_FILE);
       if (!fileOpenResult.isSuccess()) {
         Toast.makeText(this, fileOpenResult.getErrorMessage(), Toast.LENGTH_LONG).show();

Now declare the recently created activity in the AndroidManifest.xml, inside <application> tag:

        <activity android:name=".offline.MyMapActivity" />

When starting a "MyMapActivity" instance, you should see the map. for more info about creating your own .map files, see this link. Hope it helps!

2 thoughts on “Integrating MapsForge into an Android project

  1. What do you mean? You mean centering the map?
    You can call setCenter() anytime you want to move the map center. I can’t remember the parameters now, but there is a Lat,Lon parameter, and another one to enable a movement animation when centering.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s