Learn how to work with OSM map in Android app

Sana Ebadi
2 min readNov 1, 2019

--

Learn how to work with OSM map in Android app

OpenStreetMap, or OSM for short, is another type of map available for Android developers to use in their applications.

You may be aware that using Google Map is a common and very useful way to use the map and its features but due to recent restrictions Google has made to developers it is only free to show the map itself, but in some cases Like location tracking and other features, approximately 25,000 usernames are free, but then about 50 cents per 1,000,000 users must be paid.

Being monetary makes little sense for developers to use free maps such as OSM, which of course, being open-source, has led many developers to work together.

An overview of how Google Maps looks compared to OpenStreetMap

How to add OSM to our app?

So this article is going to talk about how to implement an OSM map and also show a KML file so let’s get started.

First, you need to add the dependencies needed to your build.gradle application level and project:

Now open the project’s Manifest.xml file and add the necessary permissions t :

Then go to the layout.xml you want to show the map and apply this map tag:

So finally go to your Java class and add the following code:

Well in the above codes you see duplicate codes for dangerous applications in the runtime and also the implementation of the map. You can follow the comments.

How to display KML on the OSM map in Android programming?

Next, as we mentioned earlier, we were going to map and display KML files on the map. To do this, first place the file in the raw folder (right-click res and New> Android Resource Dir And select the directory from the raw) Then do the following with its specific code and codes:

And in onCreate, we’ll call this method load Kml and the whole OsmActivity class will be as follows:

Finally, you see The map and kml file (Click ON Map)like this :

The Final Result

We also have another option called UTM, which we will explain in later articles. To view and download this source code, you can also visit my GitHub.

Sana Ebadi | 19:36 PM, Friday 01 November 2019

--

--