2

I have used the Mobile Atlas creator to extract the map tiles for a selected area on the map. The result is a zip file contains folders (2,3,4,5,6 ...15), which represents the map zooms. inside each folder there are folders and in side the folders there are the images of the tiles.

I have used the following code to read the zip file that contains the tiles, but nothing appears on the mapview. what is the problem?

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Specify the XML layout to use:
        setContentView(R.layout.activity_main);

        // Find the MapView controller in that layout:
        m_mapView = (MapView) findViewById(R.id.mapview);

        // Setup the mapView controller:
        m_mapView.setBuiltInZoomControls(true);
        m_mapView.setMultiTouchControls(true);
        m_mapView.setClickable(true);
        m_mapView.setUseDataConnection(false);
        m_mapView.getController().setZoom(MAP_DEFAULT_ZOOM);
        m_mapView.getController().setCenter(
                new GeoPoint(MAP_DEFAULT_LATITUDE, MAP_DEFAULT_LONGITUDE));

        // save zip to sd
        AssetManager assetManager = this.getAssets();
        InputStream is;
        String fileName = "Layer.zip"; // the zip file lies in assets root
        String path = this.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");

        MapTileModuleProviderBase[] providers = new MapTileModuleProviderBase[2];
        providers[0] = new MapTileFileArchiveProvider(
                new SimpleRegisterReceiver(getApplicationContext()),
                customTiles);
        //providers[1] = new MapTileDownloader(TileSourceFactory.MAPNIK);

        m_mapView.setUseDataConnection(true);

        MapTileProviderArray tileProvider = new MapTileProviderArray(
                customTiles, new SimpleRegisterReceiver(
                        this.getApplicationContext()), providers);

        TilesOverlay tilesOverlay = new TilesOverlay(tileProvider,
                getApplicationContext());
        tilesOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);

        m_mapView.getOverlays().add(tilesOverlay);

        m_mapView.invalidate();

        // m_mapView.setTileSource(TileSourceFactory.MAPNIK);
    } // end onCreate()

} 
Adham
  • 63,550
  • 98
  • 229
  • 344
  • 1
    Duplicate with numerous posts. Answer here: http://stackoverflow.com/questions/22862534/download-maps-for-osmdroid/22868462#22868462 – MKer Sep 08 '14 at 11:37

0 Answers0