OsmDroid + Mobile Atlas Creator tutorial

As you may know, Mobile Atlas Creator (from now on, MOBAC) was blocked due to producing high stress on OSM servers, since mid-2013.

So MOBAC can’t generate Mapnik tiles now, and most of the OsmDroid Apps use Mapnik.

What we’re gonna do in this tutorial is to use MapQuest tiles, the ones that MOBAC actually support, instead of Mapnik tiles.

In MOBAC:

Select “Atlas > New Atlas”

Select the “OSMDroid ZIP” option

Now on the atlas, select “Map Source: OpenStreetMaps mapquest”

mapsource

Mark the “Recreate/adjust map tiles (CPU intensive)” checkbox

tileformat

Choose “Tile format: PNG”. To make sure this is correctly done, select another one (like JPEG) and then switch back to PNG.

Drag the area you wish to select and mark the Zoom Levels you want to include in your atlas

dragdrop

Click on atlas name (mine is “Unnamed atlas”), then click on Add Selection. A new layer must be created.

addselection

Then on the upper menu, click Atlas > Create atlas

Now you’ll find a .zip file inside your MOBAC folder. Extract it into a temporary folder.

Rename the “MapQuest” folder inside the zip to “MapquestOSM”, and zip it again (pay attention to the caps). Don’t worry about the name of the zip. “MapquestOSM.zip” would be OK, but its not strictly necessary.

copy the new zip file to /sdcard/osmdroid/ (not inside /sdcard/osmdroid/tiles!, just osmdroid folder)

Android code to load the atlas:

public class MyMapActivityBasic extends Activity
  protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   MapView mapView = new MapView(this, 256); //constructor
   mapView.setClickable(true);
   mapView.setBuiltInZoomControls(true);
   setContentView(mapView); //displaying the MapView
   mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);
   mapView.getController().setZoom(15); //set initial zoom-level, depends on your need
   mapView.getController().setCenter(new GeoPoint(mLat, mLon));
   mapView.setUseDataConnection(true); 
   mapView.setMultiTouchControls(true);
 }
}
Advertisement

Usual mistake when creating IntentServices

Do not forget to override the public empty constructor, or the service won’t launch
– Even if it’s correctly declared in the AndroidManifest.xml file
– Even if it has onHandleIntent() correctly overridden.

Example code:

public class MyService extends IntentService{
    public MyService(){
         super(null);
     }
 
    public MyService(String name) {
         super(name);
    }
    @Override
    protected void onHandleIntent(Intent intent) {
        //...
    }
 }

Google Maps API v2: All i get is an empty map

If you have correctly done all the steps to configure your GoogleMap, and you just see an empty map with a [+/-] zoom control, you probably havent registered your debug key in Google APIs console.

To find your debug SHA1 key:

running a terminal inside HOME directory (Linux: /home/user/, Windows: C:\Users\user\, etc)

 

keytool -list -v -keystore .android/debug.keystore

It will ask you for a password, leave it empty and press enter. You will see the SHA1 key, that looks like this:

Certificate fingerprints:
 MD5: BA:3C:6D:7A:4C:4A:AD:3E:65:DB:53:D1:3A:23:A3:4D
 SHA1: B5:38:93:50:7C:EA:55:23:51:1E:BC:EE:AA:A5:6D:A8:6C:B7:16:35

To register the debug SHA1 as allowed app in Google APIs Console

Now, on Google APIs console, go to the “API Access” section and generate a new allowed key for an app. As the value, attach your app’s package name to the SHA1 key separated by a | character. Like this.:

B5:38:93:50:7C:EA:55:23:51:1E:BC:EE:AA:A5:6D:A8:6C:B7:16:35|com.example.mymapsproject

So now, your allowed apps list should look like this:

Key for Android apps (with certificates)
 API key:
 Whatever_the_api_key_is
 Android apps:
 XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX;com.example.mymapsproject
 B5:38:93:50:7C:EA:55:23:51:1E:BC:EE:AA:A5:6D:A8:6C:B7:16:35;com.example.mymapsproject
 Activated on: Date, Time

one line for the “production” signature, and another line for the debug signature. Note that the character beetween the SHA1 and the package name used to be “|” for previous versions of Google APIs, but now is a semicolon “;”.

Hope it helps!

original source

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:

Windows

“C:\Users\user_name\.m2\repository\org\mapsforge\mapsforge-map.3.1-SNAPSHOT”

Linux

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” (org.mapsforge.android.maps.MapActivity).

public class MyMapActivity extends MapActivity{
    private static final File MAP_FILE = new File(Environment.getExternalStorageDirectory().getPath(), "mymap.map");
     @Override
     protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       MapView mapView = new MapView(this);
       mapView.setClickable(true);
       mapView.setBuiltInZoomControls(true);
       FileOpenResult fileOpenResult = mapView.setMapFile(MAP_FILE);
       if (!fileOpenResult.isSuccess()) {
         Toast.makeText(this, fileOpenResult.getErrorMessage(), Toast.LENGTH_LONG).show();
         finish();
       }
       setContentView(mapView);
    }
 }

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

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

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!