0

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)

snotyak
  • 3,709
  • 6
  • 35
  • 52
  • 1
    "Seeing as Google Maps now provides you with the ability to do Offline Caching yourself, why would it still be illegal?" -- for starters, it is not supported. You are confusing the Google Maps application (which has offline caching) with the Google Maps SDK add-on for Android (which does not have offline caching). They are approximately as related as is Neanderthal to Cro-Magnon. – CommonsWare Sep 09 '12 at 22:31

1 Answers1

1

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.

NickT
  • 23,844
  • 11
  • 78
  • 121
  • Unfortunately, my issue was that my tile files were .png rather than .png.tile. Everything else in my code was perfectly fine. Do you have any suggestions as to restricting the viewable area? – snotyak Sep 09 '12 at 21:09
  • I've not restricted the area myself but I believe it should be possible. Certainly if the map is in 'GPS centring mode' (i.e centre the map on what the GPS gives you) you can put bounds on the lat/longitude. If it's in pan mode (i.e don't follow the GPS, but user drags the map instead) it might be more difficult. – NickT Sep 09 '12 at 21:23
  • It looks I can bound it by using this: http://code.google.com/p/osmdroid/issues/attachmentText?id=209&aid=2090027000&name=BoundedMapView.java&token=u-BtTELHn7ZFNILgm7OdNfPIn00%3A1345308728441 – snotyak Sep 09 '12 at 22:29