osmdroid

OSMDroid offline maps not loading


Using osmdroid I am trying to build an offline mapping app.

I am using map tiles which I generated from a file server in PNG format. These are organised in the standard /x/y/z.png file/directory structure and compressed into a .zip file with the internal structure: /mapnik/x/y/z.png

The name of the .zip file is mapnik.zip (I understand the name of this file doesn't matter).

I installed my .apk by buiding it in Android Studio.

I have tried putting the .zip file in /storage/emulated/0/osmdroid and /storage/emulated/0/osmdroid/tiles which is where the cache.db and cache.db-journal files reside (this directory structure existed already).

When I run the app it runs but shows a blank grid instead of a map.

If I change map.setUseDataConnection(false); to (true) it loads the map over the internet and displays it.

Unfortunately I need this to run uniquely offline.

The code for this I got from https://github.com/TizioFittizio/OsmDroidOfflineMap

My MainActivity is as follows:

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MapView map = (MapView) findViewById(R.id.map);
        map.setUseDataConnection(false);

        map.setTileSource(TileSourceFactory.MAPNIK);

        IMapController controller = map.getController();
        GeoPoint startPoint = new GeoPoint(37.370925, -5.972684);
        controller.setCenter(startPoint);
        Marker startMarker = new Marker(map);
        startMarker.setPosition(startPoint);
        startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
        map.getOverlays().add(startMarker);

        controller.setZoom(8);
        map.setMinZoomLevel(6);
        map.setMaxZoomLevel(15);

Does anybody know what I'm doing wrong?

Alternatively, has anyone else done this and did you use osmdroid? And if not, what did you use?


Solution

  • within your zip, it should have the following structure

    /
    /tileSource
    /tileSource/0/0/0.png
    

    where tile source, in your case, should be Mapnik exactly. i.e. map.setTileSource(TileSourceFactory.MAPNIK); must match the tile source name. Check out the source for TileSourceFactory to get an idea of how to create your own ITileSource. To get an idea of how the path is created, it is here.

    there's also a sample dataset here which would use a tile source with the name of cb-wac

    if you are still having problems, Configuration.getInstance().setDebugMode(true)); Configuration.getInstance().setDebugTileProviders(true)); may help with debugging