I've researched a bit into this topic and have discovered that the last time this was asked (specifically for Google Maps), the answer was "it's illegal". Seeing as Google Maps now provides you with the ability to do Offline Caching yourself, why would it still be illegal?
Anyway, I have an app that I need to package a small map for (a few square miles). I've looked into doing osmdroid but it's very difficult to follow what they're doing. I've looked at their SVN repo's and checked out their sample app on the Play Store and was disappointed. The app itself shows pretty much exactly what I need, but it uses some weird form of their code, not included in the SDK. osmdroid seems like my best option at this point but there doesn't seem to be much references available.
If anyone could point me into the right direction of getting started with osmdroid OR just some other SDK that allows for packaged maps, I'd greatly appreciate it.
Note: I've tried doing it in osmdroid but when doing
mapView.setUseDataConnection(false);
The map loads nothing, even though the files appear to be in the correct directory (as it downloads all of its files there as well)
To use Osmdroid like Google Maps you just need a couple of jar files in your project one being osmdroid-android-3.0.x.jar (for x - I've used version 5 and version 7 ). The other jar is the slf4j-android-1.5.8.jar. (There might be later versions of this, can't remember where I got it from but there should be a link on the Osmdroid web site somewhere). The code is very similar to Google maps. This is the smallest working example I could produce
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;
// This is all you need to display an OSM map using osmdroid
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.MAPNIK);
mMapView.setBuiltInZoomControls(true);
mMapController = mMapView.getController();
mMapController.setZoom(13);
GeoPoint gPt = new GeoPoint(51500000, -150000);
//Centre map near to Hyde Park Corner, London
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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<org.osmdroid.views.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mapview"
></org.osmdroid.views.MapView>
</LinearLayout>
---------------------------------------------------------- XML END
Include slf4j-android-1.5.8.jar and osmdroid-android-3.0.5.jar in the build path
(Google search for where to get them from)
*/
As for offline caching use Mobile Atlas creator (MOBAC) to make an Atlas in Osmdroid Zip format of the area of interest. I use OpenStreetMap as the tile source. Once you have the zip file just drop it into the Osmdroid directory on your device. It should give you offline capability. I use it all the time in my own app in London with packet data turned off in order to keep data downloads (and their cost) down.