Good day to all! I want to build OSMdroid offline maps into my application, I tried a lot of options: Manifest:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 

The Internet did not connect for offline maps, and the Internet is not used. In the standard layout:

 <org.osmdroid.views.MapView android:id="@+id/map" android:layout_width="fill_parent" android:layout_height="fill_parent" /> 

In the code I tried this example:

 public View onCreateView(LayoutInflater inflater,ViewGroup parent,Bundle savedInstanceState){ View v = inflater.inflate(R.layout.fragment_main,parent,false); myOpenMapView = (MapView)v.findViewById(R.id.openmapview); myOpenMapView.setUseDataConnection(false); //work from directory osmdroid myOpenMapView.setTileSource(TileSourceFactory.MAPQUESTOSM); myOpenMapView.setBuiltInZoomControls(true); myOpenMapView.setMultiTouchControls(true); myOpenMapView.setMaxZoomLevel(15); myOpenMapView.setMinZoomLevel(12); BoundingBoxE6 bbox = new BoundingBoxE6(46.520131,30.774078,46.451105,30.686188); myOpenMapView.setScrollableAreaLimit(bbox); myMapController = (MapController) myOpenMapView.getController(); myMapController.setZoom(15); myMapController.setCenter(new GeoPoint(46.46766, 30.726013)); return v; } 

does not see the archive with the cards. Tried and by this example:

 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DefaultResourceProxyImpl resProxy; resProxy = new DefaultResourceProxyImpl(this.getApplicationContext()); XYTileSource tSource; tSource = new XYTileSource("mbtiles", ResourceProxy.string.offline_mode, 8, 15, 256, ".png", "http://who.cares/"); SimpleRegisterReceiver sr = new SimpleRegisterReceiver(this); String packageDir = "/Maps"; String p = Environment.getExternalStorageDirectory() + packageDir; File f = new File(p, "HollandRoute.mbtiles"); IArchiveFile[] files = { MBTilesFileArchive.getDatabaseFileArchive(f) }; MapTileModuleProviderBase moduleProvider; moduleProvider = new MapTileFileArchiveProvider(sr, tSource, files); MapTileModuleProviderBase[] pBaseArray; pBaseArray = new MapTileModuleProviderBase[] { moduleProvider }; MapTileProviderArray provider; provider = new MapTileProviderArray(tSource, null, pBaseArray); mapView = new BoundedMapView(this, resProxy, provider); double north = 52.6297; double east = 5.3496; double south = 52.1613; double west = 4.4638; BoundingBoxE6 bBox = new BoundingBoxE6(north, east, south, west); mapView.setScrollableAreaLimit(bBox); mapView.setBuiltInZoomControls(true); // Zoom in and go to Amsterdam MapController controller = mapView.getController(); controller.setZoom(15); controller.animateTo(new GeoPoint(52.373444, 4.892229)); 

And this code did not help either:

 map.setTileSource(new XYTileSource("MapQuest", ResourceProxy.string.mapquest_osm, 0, 18, 256, ".png", new String[]{ "http://otile1.mqcdn.com/tiles/...", "http://otile2.mqcdn.com/tiles/...", "http://otile3.mqcdn.com/tiles/...", "http://otile4.mqcdn.com/tiles/..."})); 

Taken from GitHub:

 map = (MapView) findViewById(R.id.map); map.setTileSource(new XYTileSource("YOUR MAP SOURCE", 0, 18, 256, ".jpg", new String[] {})); //.... map.setUseDataConnection(false); //optional, but a good way to prevent loading from the network and test your zip loading. IMapController mapController = map.getController(); mapController.setZoom(_A ZOOM LEVEL YOU HAVE IN YOUR ZIP_); GeoPoint startPoint = new GeoPoint(_POSITION SOMEWHERE INSIDE YOUR MAP_); mapController.setCenter(startPoint); 

Just to no avail, just a grid instead of a map. The archive was created in MOBAC osmdroid ZIP, lies in on the sd card \osmdroid\Map.zip . Apparatus ALPS V9 (LandRover V9) Android 4.4.2

What am I doing wrong? Or stick your nose in the working code, I'm not strong in programming.

    1 answer 1

    I answer: OSMDroid does not see the archive with tiles on the SD card because the archive must be placed on EXTERNAL_SD_CARD, and the SD card inserted into the device is REMOVABLE_SD_CARD. By adding the following code to the application, you can easily determine EXTERNAL_SD_CARD

      File checkDir = new File(Environment.getExternalStorageDirectory() + "osmdroid/Maps"); if(checkDir.exists()) { Log.d("Dir", "directory exist"); } else { Log.d("Dir", "directory NOT exist"); checkDir.mkdirs(); Log.d("Dir", "directory create"); } 

    On EXTERNAL_SD_CARD, an osmdroid folder will be created with the Maps subfolder. It is in the osmdroid folder that you need to determine the zip archive with maps. Now the code is very simple:

      map.setTileSource(new XYTileSource("xUSSR.Roads.Visicom 2.0",null, 14, 19, 256, ".jpg", new String[] {})); map.setClickable(true); map.setUseDataConnection(false); map.setMaxZoomLevel(19); map.setMinZoomLevel(14); map.setBuiltInZoomControls(false); map.setMultiTouchControls(true); final GeoPoint startPoint = new GeoPoint(47.990554, 37.800179); final IMapController MC = map.getController(); MC.setCenter(startPoint); MC.setZoom(19); 

    where xUSSR.Roads.Visicom 2.0 is the source of maps, we select it in MOVAS.