How to setup OSM

Hey,
I’m gonna show you how to initialize and setup OSM.
First we need to configure our build.gradle part.

Gradle

In your root build.gradle file, add mavenLocal() if not present.
allprojects {
    repositories {
            mavenCentral()
            mavenLocal()    //add this if it's missing
    }
}
Then, add OSM’s gradle link :
compile 'org.osmdroid:osmdroid-android:5.5-SNAPSHOT:debug@aar'

Manifest

In most cases, you will have to set the following authorizations in your AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
OSM wants these user permissions, we have to add these on our Manifest

Layout

Create a “src/main/res/layouts/main.xml” layout like this one. With Android Studio, it probably created one already called. The default is “src/main/res/layouts/activity_main.xml”:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:orientation="vertical" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <org.osmdroid.views.MapView android:id="@+id/map"
                android:layout_width="fill_parent" 
                android:layout_height="fill_parent" />
</LinearLayout>
Note: It does not have to be LinearLayout, you can use whatever layout you want

Main Activity

After we configure OSM, we need to initialize our OSM map in @onCreate method:
 public class MainActivity extends Activity {
        @Override public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            MapView mMapView = (MapView) findViewById(R.id.map);


            // OSM Map Initialize
            //important! set your user agent to prevent getting banned from the osm servers
            org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants.setUserAgentValue(BuildConfig.APPLICATION_ID);
            mMapView.setTileSource(TileSourceFactory.MAPNIK);
            // Setup MapView
            setupMapView();
        }
    }

Setup OSM Method

After we’ve done onCreate method, we need to determine our map’s properties such as; zoom buttons, multi touch control, default zoom and default point.
As you can see the last two (2) lines of code setting the default map’s coordinates.
 // Setup the mapView controller:
    public void setupMapView(){
        // Zoom buttons
        mMapView.setBuiltInZoomControls(true);
        // Multitouch Controls Activation
        mMapView.setMultiTouchControls(true);
        mMapView.setClickable(true);
        // Default map zoom level:
        //private int MAP_DEFAULT_ZOOM = 20;
        mMapView.getController().setZoom(MAP_DEFAULT_ZOOM);
        // Default Point
        GeoPoint startPoint = new GeoPoint(37779300, -122419200);
        mMapView.getController().setCenter(startPoint);
    }

How to extract filename from Uri?

Now, we can extract filename with and without extension :) You will convert your bitmap to uri and get the real path of your file. Now w...