Search code examples
androidmapboxosmdroid

Use mapBox tile as osmdroid tileSource


I am new on map in android and I want to create simple map application with osmdroid. I added

implementation 'org.osmdroid:osmdroid-android:6.0.3'

to my gradle and i use in this way in ma class:

final ITileSource tileSource = TileSourceFactory.HIKEBIKEMAP;
mapView.setTileSource(tileSource);
mapView.setTilesScaledToDpi(true);
mapView.setMultiTouchControls(true);
mapView.setVisibility(View.VISIBLE);

Now i am using TileSourceFactory.HIKEBIKEMAP as a tile source. According this page I want to use mapbox tile so in order i registered in mapbox site and i created Access tokens now i can not find to create MAPBOX_MAPID where is it?

After create ID how can i use mapbox.mapbox-streets-v8?


Solution

  • The important fact to note: The mapbox.mapbox-streets-v8 is a vector tileset. Vector tiles are not directly supported by Osmdroid, only bitmap are. Fortunately, Mapbox is still provides bitmap tiles for their tilesets.

    Use mapbox.mapbox-streets-v8 ( you can also try mapbox.streets for example) as MAPBOX_MAPID and use MapBoxTileSource as described in the osmdroid documentation.

    final MapBoxTileSource tileSource = new MapBoxTileSource();
    //option 1, load your settings from the manifest
    tileSource.retrieveAccessToken(context);
    tileSource.retrieveMapBoxMapId(context);
    //option 2, provide them programmatically
    tileSource.setAccessToken(context);
    tileSource.setMapBoxMapId(context);
    mMapView.setTileSource(tileSource);
    

    It should work.