Installation guide

29
Define three variables in the public class of MainActivity in the MainActivity.java.
private MapController mapController;
private MapView mapView;
public GeoPoint point;
Consequently in the MainAcitivity.java, copy the following code exactly behind the code of
setContentView(R.layout.activity_main).
mapView = (MapView) this.findViewById(R.id.mapview);
mapView.setTileSource(TileSourceFactory.MAPNIK);
mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true);
mapController = mapView.getController();
mapController.setZoom(15);
point = new GeoPoint(59351756, 18057822);
mapController.setCenter(point);
In the res/layout/, edit the file of activity_main.xml. Double click activity_main.xml in the
Package Explorer, and select tab of activity_main.xml as it is shown in the figure below.
Delete the <TextView/> code; while add <org.osmdroid.views.MapView/> code. After
editing the activity_main.xml file will be as follows. You will also notice that the only error
in MainActivity.java is disappeared.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<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" />
</RelativeLayout>
In the file of AndroidMainfest.xml, exactly behind <uses-sdk android:minSdkVersion="7"
android:targetSdkVersion="15"/> add the following code for getting permissions.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
Now run the Android emulator as usual. You will see the OSM map if you successes.