Download maps for osmdroid
Working solution with MobileAtlasCreator / MOBAC:
There is an osmdroid documentation, but it is very weak, and sometimes outdated.
I struggled for a while on successive issues. Here are the details of a working solution with osmdroid v4.1.
1) When building your offline map with MOBAC:
- As Mapnik maps are effectively locked, select "OpenStreetMap MapQuest" as the source.
- Atlas Format: choose "Osmdroid ZIP"
- Take care to tick all zoom levels you will need. By default, none are selected.
Select your area, create your "atlas". This produces a zip file.
Upload the zip file on your device, in /sdcard/osmdroid/
(exact path may vary depending on the device. If you already used osmdroid, this directory MUST already exist)
The file name doesn't matter. The extension MUST be ".zip"
2) Now, in your osmdroid application, your onCreate method should be something like this:
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = (MapView) findViewById(R.id.map);
map.setTileSource(new XYTileSource("MapQuest",
ResourceProxy.string.mapquest_osm, 0, 18, 256, ".jpg", new String[] {
"http://otile1.mqcdn.com/tiles/1.0.0/map/",
"http://otile2.mqcdn.com/tiles/1.0.0/map/",
"http://otile3.mqcdn.com/tiles/1.0.0/map/",
"http://otile4.mqcdn.com/tiles/1.0.0/map/"}));
map.setBuiltInZoomControls(true);
map.setMultiTouchControls(true);
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);
}
In this code, 2 parameters values are VERY important:
"MapQuest" name (with this EXACT spelling) is MANDATORY => this is used as an internal path inside the zip file. If you open your zip file, you will see that MOBAC created this "MapQuest" directory.
".jpg" extension is also MANDATORY => as MOBAC creates MapQuest tiles in the zip with .jpg extension (important to notice, as standard tile sources in osmdroid are all using ".png" extension).
At this stage, it should be OK - as long as you are really positionning the mapview on an area which is part of your atlas (zoom level & position).
3) Back to MOBAC... You can also choose the following Atlas formats: "Osmdroid SQLite" or "MBTiles SQLite".
Transfert the file (Layer.sqlite or Layer.mbtiles) on the device in /sdcard/osmdroid/
Again, in your XYTileSource constructor, the extension MUST be ".jpg". The name doesn't matter.
Both worked fine.
4) Choosing "Osmdroid GEMF" format will not work: it's a known bug in GEMF on handling of jpg tiles.
EDIT > In MOBAC, you can use the "custom tile processing" feature to convert JPG tiles to PNG format. Then "Osmdroid GEMF" will be ok.
How can download map in osmdroid?
The easisest way is to download MOBAC, then run it and mark out an area you want, store the tiles in Osmdroid.zip format. When that's done, drop the zip file into the osmdroid folder on your device.
How to prepare a map tiles archive for osmdroid for offline maps?
You're supposed to use the tile packager to create your zip, or mobile atlas creator. However, if you rename all the *.tile files in your zip to *.png, it should work (not tested).
Osmdroid, use of different offline maps
Unfortunately, you can't really force osmdroid to load one specific zip.
What you can do is play with the XYTileSource name, as it must match with your root directory name inside the zip file:
map.setTileSource(new XYTileSource("Map_1",
ResourceProxy.string.mapquest_osm, 0, 18, 256, ".png", new String[] {
"http://otile1.mqcdn.com/tiles/1.0.0/map/",
"http://otile2.mqcdn.com/tiles/1.0.0/map/",
"http://otile3.mqcdn.com/tiles/1.0.0/map/",
"http://otile4.mqcdn.com/tiles/1.0.0/map/"}));
will only use zip files structured like this:
+-- Map_1
+-- 10
¦ +-- 550
¦ +-- 335.png
...
Also refer to: Download maps for osmdroid
Related Topics
How Do Mpandroidchart Renderers Work and How to Write a Custom Renderer
Android Http Connection Exception
How to Dismiss a Progress Bar Even If There Is No View to Populate in the Firebaselistadapter
Current Month Facebook Friends Birthdays in Android
How to Have Searched Characters Colored When We Use Searchview in Recyclerview
Gradle Dsl Method Not Found: 'Runproguard'
Android:Locationmanager VS Google Play Services
Add Shadow to Custom Shape on Android
Debugging SQLite Database on the Device
Android Get Current Locale, Not Default
Android Facebook 4.0 Sdk How to Get Email, Date of Birth and Gender of User
Android: Determine Security Type of Wifi Networks in Range (Without Connecting to Them)
Using Picasso with Custom Disk Cache
Google Places API Request Denied for Android Autocomplete, Even with the Right API Key
Android Youtube Upload Video with Static Username and Password