I am searching for a tutorial/manual or steps to include Open street map into my android application. All I found is either a big project with lot more functionality on it, othe
One mistake that people using Google Maps like service make is that they treat OpenStreetMap as just map tile provider. You need to know that OpenStreetMap is actually a big free editable wiki geodatabase and there are three different ways you can use this database.
You can make tools to write to this database. There is REST Api https://wiki.openstreetmap.org/wiki/API_v0.6 . This is what you use if you have to make changes to the database. This is the least common use case but is most thoroughly documented. The API is main OSM API and can be used to download data as well but it is not the recommended way to download OSM data.
Next you can read data from this database. The best way to do is to download planet extracts https://wiki.openstreetmap.org/wiki/Planet.osm and smaller extracts hosted by geofabrik http://download.geofabrik.de/. If you want to make more specific queries, best options could be Overpass API https://wiki.openstreetmap.org/wiki/Overpass_API.
Finally there are a range of service that are built on top of OSM data like (map tiles, routing, POI search, geocoding). This is most probably what you are looking for there are lot of options for this. For Android a good complete solution is Mapbox https://www.mapbox.com/android-docs/map-sdk/overview/ . The great thing about mapbox android sdk is that they provide everything like map tiles, routing, POI search, geocoding, offline maps and even live traffic using one service. Also you can follow the above link and look at tutorials and sample code. One bad thing is that you will need to use mapbox service and there is a risk of vendor lock in, but most of mapbox products are open source. If you work a little hard you should be able to piece together other solutions for yourself as well.
Hope this helps.
OSM is really great but hard to use specially with it's google api and also there isn't much tutorials and docs for it, the best option will be using services like mapbox which have great docs and a lot of sources, easy to use and affordable. hope this will help.
This OSMdroid sample project is definitely the simplest that i have come across. No more than 5 minutes to be up and running. Pay attention to the manifest file.
For a bit more complexity, this tutorial displays a map with a current geopoint.
Here are some snippets from various projects. Haven't tested all of them, though.
You should download OSMdroid and SLF4J, place in libs
folder, Add as Library
osmdroid, fix AndroidManifest.xml with proper permissions (see first tutorial). If you do this, there is no need to alter gradle.build
file as recommended in first tutorial.
I recommend that you use, for starters, the older versions of osmdroid (3.x) when using these. Once you are comfortable, migrate to newer version of osmdroid (4.x or 5.x).
GeoPoint and MapController classes change names in newer versions, so watch out for INCOMPATIBLE TYPES ERROR
IGeoPoint cannot be converted to GeoPoint
IMapController cannot be converted to MapController
I don't know of any tutorials but here's the code I wrote for a minimal example using Osmdroid.
// This is all you need to display an OSM map using osmdroid
package osmdemo.demo;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import android.app.Activity;
import android.os.Bundle;
public class OsmdroidDemoMap extends Activity {
private MapView mMapView;
private MapController mMapController;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.osm_main);
mMapView = (MapView) findViewById(R.id.mapview);
mMapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
mMapView.setBuiltInZoomControls(true);
mMapController = (MapController) mMapView.getController();
mMapController.setZoom(13);
GeoPoint gPt = new GeoPoint(51500000, -150000);
mMapController.setCenter(gPt);
}
}
/* HAVE THIS AS YOUR osm_main.xml
---------------------------------------------------------- XML START
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<org.osmdroid.views.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
</LinearLayout>
---------------------------------------------------------- XML END
Include slf4j-android-1.5.8.jar and osmdroid-android-4.1.jar in the build path
(Google search for where to get them from)
*/
Note that you must now use the latest version (4.1) to avoid getting blocked from downloading tiles from OSM.
Also note that they are moving their repositries to Github and the process isn't complete yet. This page downloads holds the links for the jars
I have explained the steps HERE. I also recommend you take a look at their Sample Project which is very useful. And their documentation about HOW ;)
And for Offline Use
1- you must download the map using MOBAC.
2- Place it into /mnt/sdcard/osmdroid/
After these steps everything is the same as @Nick explained.