Search code examples
androidmapboxmbtiles

Mapbox Android SDK with online custom MBTiles


I have started to build an android apps using Mapbox Android SDK. I want to use my custom mbtiles file created from Tilemill. I was following this instruction

Code to Display the Tilemills mbtiles in android project

I have successfully implemented this code and working fine. But the problem, when I am building APK its becoming a huge file as my MBTiles file is too big. This is why its taking long to open the apps. Is there any way to get access the MBTiles file from online server storage such as http://www.example.com/mymap.mbtiles? I have tried the MapView Activity with the following code but didn't get any luck

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setZoom(10);
        mapView.setCenter(new LatLng(38.8977, -77.0365));
        mapView.setTileSource(new MBTilesLayer(this, "http://www.example.com/mymap.mbtiles"));

The XML file contains

<com.mapbox.mapboxsdk.views.MapView
    android:id="@+id/mapview
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

Solution

  • It seems to me the API you've used in your question is now deprecated in favor of the mapbox-gl-native project. However, from what I found in other answers here and on GitHub there might be a way to achieve what you want to do:

    1. Extract your .mbtiles file into .png tile files and a .json file using mb-util.
    2. Host these file on a server.
    3. Use TileJsonTileLayer instead of MBTilesLayer to access the online tiles. An attempt to do this can be found at issue #742 of the mapbox-android-sdk-legacy project.

    If it doesn't work I'm sorry. This is the best I can come up with at the moment as I don't have the time to implement it myself.