我是 Android 应用程序开发的新手,我必须创建一个离线地图 Android 应用程序。
我使用 Mobile Atlas Creator 获取地图视图 osmdroid .zip 格式,但我不知道如何将其添加到我的应用程序中。
有人可以告诉我如何在我的应用程序中使用 Osmdroid 吗?如果您能提供分步说明,我将不胜感激。
这是我前段时间为 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;
// This is all you need to display an OSM map using osmdroid
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.MAPNIK);
mMapView.setBuiltInZoomControls(true);
mMapController = mMapView.getController();
mMapController.setZoom(13);
GeoPoint gPt = new GeoPoint(51500000, -150000);
//Centre map near to Hyde Park Corner, London
mMapController.setCenter(gPt);
}
}
把这个放在你的osm_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<org.osmdroid.views.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mapview" />
</LinearLayout>
在构建路径中包含slf4j-android-1.5.8.jar
和。osmdroid-android-3.0.5.jar
(谷歌搜索从哪里得到它们)