【问题标题】:Creating an offline map on Android在 Android 上创建离线地图
【发布时间】:2011-11-23 18:03:40
【问题描述】:

我是 Android 应用程序开发的新手,我必须创建一个离线地图 Android 应用程序。

我使用 Mobile Atlas Creator 获取了 osmdroid .zip 格式的地图视图,但我不知道如何将其添加到我的应用中。

谁能告诉我如何在我的应用程序中使用 Osmdroid?如果您能提供分步说明,我将不胜感激。

【问题讨论】:

    标签: java android eclipse osmdroid


    【解决方案1】:

    这是我前段时间为 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.jarosmdroid-android-3.0.5.jar。 (谷歌搜索从哪里得到它们)

    【讨论】:

    • 谢谢你的回答,你能告诉我如何调用从 Mobile Atlas Creator 中提取的视图还是自动的?
    • 它是自动的,只需将 zip 文件放到手机上的文件夹 /sdcard/osmdroid 中
    • thx NickT 它起作用了,你能告诉我在模拟器中我应该把 pic .zip 放在哪个文件夹中吗
    • 在模拟器中启动应用程序后,如果您转到 DDMS 视图,请打开文件资源管理器选项卡。将有 3 个文件夹可见 - 将 zip 文件放在“sdcard”文件夹中
    • 我这样做了,但没有用,我只有一个空视图,没有地图请帮助我。你能告诉我从哪里得到 GeoPoint gPt = new GeoPoint(51500000, -150000);我的意思是地理点的经度和纬度
    猜你喜欢
    • 2011-11-29
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 2012-07-01
    • 1970-01-01
    • 2019-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多