Search code examples
androidosmdroidoffline-mode

Saving OSM map tiles in app project


Just wondering is it possible to add the saved map tiles from the mobile atlas to the project instead of sd card?

i want the map tiles to be available within the app i will be releasing. It is a free app on android market.

The map tiles are divided into 4 zip files, is it possible to keep and use them from the project file or do i need an online server to download them from.

Any help would be great

Thank you


Solution

  • One options is to use the assets folder to store files and then copy them to your private app data directory. Something like this should work. This copies a database, but you could adapt it to copy your zip files.

    /**
     * Copies your database from your local assets-folder to the just created empty database in the
     * system folder, from where it can be accessed and handled. This is done by transfering
     * bytestream.
     * */
    private void copyDataBase() throws IOException {
    
        // Open your local db as the input stream
        InputStream myInput = mContext.getAssets().open(DB_NAME);
    
        // Path to the just created empty db
        String outFileName = DB_PATH.toString();
        // boolean success = DB_PATH.mkdirs();
    
        // Open the empty db as the output stream
        OutputStream myOutput = new FileOutputStream(outFileName);
    
        // transfer bytes from the inputfile to the outputfile
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer)) > 0) {
            myOutput.write(buffer, 0, length);
        }
    
        // Close the streams
        myOutput.flush();
        myOutput.close();
        myInput.close();
    
    }