it's a simple example to implement OpenStreetMapView on Android.
Modify main.xml to include org.osmdroid.views.MapView.
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
android:id="@+id/openmapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
Main activity, AndroidOpenStreetMapViewActivity.java
package com.exercise.OpenStreetMapView;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import android.app.Activity;
import android.os.Bundle;
public class AndroidOpenStreetMapViewActivity extends Activity {
private MapView myOpenMapView;
private MapController myMapController;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myOpenMapView = (MapView)findViewById(R.id.openmapview);
myOpenMapView.setBuiltInZoomControls(true);
myMapController = myOpenMapView.getController();
myMapController.setZoom(4);
}
}
Modify AndroidManifest.xml to add uses-permission of "android.permission.ACCESS_NETWORK_STATE", "android.permission.INTERNET" and "android.permission.WRITE_EXTERNAL_STORAGE".
package="com.exercise.OpenStreetMapView"
android:versionCode="1"
android:versionName="1.0" >
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
android:name=".AndroidOpenStreetMapViewActivity"
android:label="@string/app_name" >

Next:
- Update location on OpenStreetMap
0 تعليقات