Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8995821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:40:14+00:00 2026-06-15T23:40:14+00:00

So I’ve finally gotten osmdroid working with a local directory but I’d like to

  • 0

So I’ve finally gotten osmdroid working with a local directory but I’d like to load tiles from Mapnik when they are missing locally. I’m not sure what I’m missing.

My implementation is as follows:

private MapView mapView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.osm_map);

    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);
    mapView.setMultiTouchControls(true);

    MapController mapController = mapView.getController();
    mapController.setZoom(5);
    GeoPoint point2 = new GeoPoint(55708545, 10006348);
    mapController.setCenter(point2);

    //TODO Save to SD
    AssetManager assetManager = getAssets();
    InputStream is;
    String fileName = "test.zip";
    String path = Environment.getExternalStorageDirectory() + File.separator + fileName;    //TODO Path to save it to
    try {
        is = assetManager.open(fileName);

        FileOutputStream fo = new FileOutputStream(path);

        byte[] b = new byte[1024];
        int length;
        while((length = is.read(b)) != -1) {
            fo.write(b, 0, length);
        }
        fo.flush();
        fo.close();
        is.close();
    } catch (IOException  e) {
        e.printStackTrace();
    }

    File tileFile = new File(path);
    IArchiveFile[] archives = new IArchiveFile[1];
    archives[0] = ArchiveFileFactory.getArchiveFile(tileFile);

    CustomTileSource customTiles = new CustomTileSource("Mapnik", null, 0, 24, 256, ".png");    // the name should match the name of the folder that is zipped

    MapTileModuleProviderBase[] providers = new MapTileModuleProviderBase[2];
    providers[0] = new MapTileFileArchiveProvider(new SimpleRegisterReceiver(getApplicationContext()), customTiles, archives);
    providers[1] =  new MapTileDownloader(TileSourceFactory.MAPNIK);
    mapView.setUseDataConnection(false);
    mapView.setTileSource(TileSourceFactory.MAPNIK);

    MapTileProviderArray tileProvider = new MapTileProviderArray(customTiles, null, providers);
    TilesOverlay tilesOverlay = new TilesOverlay(tileProvider, getApplicationContext());
    mapView.getOverlays().add(tilesOverlay);
    mapView.invalidate();
}

AND

public class CustomTileSource extends BitmapTileSourceBase {

    public CustomTileSource(String aName, string aResourceId,
            int aZoomMinLevel, int aZoomMaxLevel, int aTileSizePixels,
            String aImageFilenameEnding) {
        super(aName, aResourceId, aZoomMinLevel, aZoomMaxLevel, aTileSizePixels,
                aImageFilenameEnding);
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:40:14+00:00Added an answer on June 15, 2026 at 11:40 pm

    Okay so I’ve finally found a solution. Its quite complex and long but it works 😀

    Now inside my OsmDroidFragment (yes map in fragment) I have following:

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        RelativeLayout view = (RelativeLayout) inflater.inflate(R.layout.osm_map, container, false);
        RelativeLayout mapContainer = (RelativeLayout) view.findViewById(R.id.osm_map_parent);
    
        mMapView = new OsmCustomMapView(getActivity(), 256, 10, 13);    // I've made a custom implementation in order to limit zoom, you can just use regular osmdroid mapview
        LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        mMapView.setLayoutParams(params);
        mapContainer.addView(mMapView);
    
        mMapView.setBuiltInZoomControls(true);
        mMapView.setMultiTouchControls(false);  // pinch zoom works bad on osmdroid
    
        MapController mapController = mMapView.getController();
        mapController.setZoom(11);  // must set zoom before setCenter, else we get the wrong position
        GeoPoint center = new GeoPoint(0,0);
        mapController.setCenter(center);
    
        // save zip to sd
        AssetManager assetManager = getActivity().getAssets();
        InputStream is;
        String fileName = "map.zip";    // the zip file lies in assets root
        String path = this.getActivity().getExternalFilesDir(null) + File.separator + fileName; // the path I save SD to
    
        File tileFile = new File(path);
        if(!tileFile.exists()) {
            try {
                is = assetManager.open(fileName);
    
                FileOutputStream fo = new FileOutputStream(path);
    
                byte[] b = new byte[1024];
                int length;
                while((length = is.read(b)) != -1) {
                    fo.write(b, 0, length);
                }
    
                fo.flush();
                fo.close();
                is.close();
            } catch (IOException  e) {
                e.printStackTrace();
            }
        }
    
        IArchiveFile[] archives = new IArchiveFile[1];
        archives[0] = ArchiveFileFactory.getArchiveFile(tileFile);
    
        // Simple implementation that extends BitmapTileSourceBase and nothing else
        CustomTileSource customTiles = new CustomTileSource("Maverik", null, 10, 14, 256, ".png");  // Maverik is the name of the folder inside the zip (so zip is map.zip and inside it is a folder called Maverik)
    
        MapTileModuleProviderBase[] providers = new MapTileModuleProviderBase[2];
        providers[0] = new MapTileFileArchiveProvider(new SimpleRegisterReceiver(getActivity().getApplicationContext()), customTiles, archives);    // this one is for local tiles (zip etc.)
        providers[1] =  new MapTileDownloader(TileSourceFactory.MAPNIK);    // MAPNIK web tile source
    
        mMapView.setUseDataConnection(true);
    
        MapTileProviderArray tileProvider = new MapTileProviderArray(customTiles, 
                new SimpleRegisterReceiver(getActivity().getApplicationContext()), providers);
        TilesOverlay tilesOverlay = new TilesOverlay(tileProvider, getActivity().getApplicationContext());
        tilesOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);  // this makes sure that the invisble tiles of local tiles are transparent so we can see tiles from web, transparent have a minor performance decline.
    
        mMapView.getOverlays().add(tilesOverlay);
    
        mMapView.invalidate();
    
        return view;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.