Offline Maps in Android with OpenStreetMap — A Complete Guide.
Want to add offline maps to your Android app without relying on paid mapping services? OpenStreetMap (OSM) is a powerful, free, and open-source alternative that lets you integrate customizable, offline-friendly maps into your project.
In this guide, we’ll cover:
✅ What is OpenStreetMap (OSM)?
✅ Types of map tiles (Raster vs. Vector) & their differences
✅ Best libraries for rendering offline vector tiles on Android
✅ How to build an offline map app using the Mapsforge library
By the end, you’ll have a working offline OpenStreetMap-based Android app without needing a tile server. Let’s get started! 🚀
What is OpenStreetMap 🌍?
OpenStreetMap (OSM) provides open map data that is built by a community of mappers around the world and maintains the info about roads, trails, hospitals, railway stations, and much more.
Why OSM ?
Because OpenStreetMap is free and open map data and it is community driven means you are free to use it for any purpose as long as you credit OpenStreetMap and its contributors.
“Used in popular free navigation apps like Organic Maps and OsmAnd”
“No licensing fees like Google Maps”
More about OSM see FAQ WIKI and License.
🗺️Map tiles available in OSM ?
Map rendering refers to the process of taking raw geospatial data and making a visual map from it.
There are two different types of tiles:
- Raster tiles
- Vector tiles
Raster tiles are just pre-rendered images, (ex: here) and they are displayed in a grid arrangement to form a visual map. Raster maps are usually harder to customize on the client side and require a tile server.
Vector tiles are just like raster tiles, but instead of pre-rendered images as a tile, the return data contains map data, thus adding complexity to the client application that they need to render its data on the fly to form a visual representation of map in it.
Also, vector tiles address some limitations of raster tiles, like. Customization, smooth zooming and more. Read more about it here.
Note: In this article we are focused on the Vector tile rendering library on Android, because it is easy to implement it on an offline OSM-based map app, and it doesn’t require a tile server.
As I mentioned earlier, vector maps are somewhat complex to render them on the client side (Mobile, Desktop, and Web) because they only contain map data. Fortunately, the rendering libraries handle the complex tasks for us. We will see these libraries in the details in the next section.
Offline Vector Rendering libraries
In this section, we are more specifically going to explore the available libraries for rendering offline vector map based on OSM for Android & Java platforms.
Apart from these mentioned libraries, there are other libraries as mentioned in the Android Wiki of OSM. The reason why I am not listing those libraries is because they often have a vendor-lock-in, which means proprietary licensing terms and don’t completely support the offline maps.
Integrating Offline OSM Maps in an Android App
In today’s article I am going to show an example of Mapsforge library as a vector map renderer for android, because it fully supports offline maps, and has a lot of online map providers.
Note: I am not a member or a contributor of any listed libraries here, and I am not promoting any libraries, so, it is full of my research effects and things I learnt that I am happy to share with you without expecting any profits.
Let’s begin by adding the necessary dependencies for Mapsforge. Check out the latest version here.
// Mapsforge Core
implementation ("org.mapsforge:mapsforge-core:0.23.0")
implementation ("org.mapsforge:mapsforge-map:0.23.0")
implementation ("org.mapsforge:mapsforge-map-reader:0.23.0")
implementation ("org.mapsforge:mapsforge-themes:0.23.0")
// Android dependencies for Mapsforge
implementation ("org.mapsforge:mapsforge-map-android:0.23.0")
implementation ("com.caverock:androidsvg:1.4")
// Mapsforge POI core (OPTIONAL)
implementation ("org.mapsforge:mapsforge-poi:0.23.0")
// Mapsforge POI android specific (OPTIONAL)
implementation ("org.mapsforge:mapsforge-poi-android:0.23.0")
Here, we are going to create a basic application (see MapForgeMapView.java ) that renders the osm vector map that is already stored in our mobile file system. Download the map that you want to display in the app.
And its corresponding MainActivity.kt
This is only a simple demo. Mapsforge can do more than this. Don’t forget to read all the docs on the Mapsforge page.
As I mentioned previously, vector tiles can be easily styled. The mapsforge library also supports styling using the XML format. See here for more details. I am also working on an OSM-based offline map app, which is in an development state right now.
Contributing to OpenStreetMap
If you want to give back to the community and improve OpenStreetMap by adding missing places or updating existing data, you’re always welcome! Several tools make contributing easy:
- On Android: Use StreetComplete — Easy to use OpenStreetMap editor for Android
- On Desktop: Use JOSM (Java OpenStreetMap Editor) — A powerful tool for advanced editing and customization.
Conclusion
I hope you found this article helpful! If you appreciate my research and effort, 🙏 please consider liking 👏 and sharing it . Your support motivates me to continue creating high-quality, free content for everyone. Happy mapping!🌍