【问题标题】:android mapping using osmDroid mapping api使用osmDroid映射api的android映射
【发布时间】:2012-04-27 01:40:27
【问题描述】:

我想使用具有离线和在线功能的 osmDroid 映射 api 开发 android 映射应用程序,但我找不到很多关于它的教程,所以如果有人有任何链接到使用 osmdroid 映射 api 离线或在线的教程。 我编写了一个小应用程序只是为了显示来自默认提供程序的地图,但是应用程序运行但没有显示地图(仅显示)有什么问题?代码:

MapView map = new MapView(this, 256);
    map.setClickable(true);
    map.setBuiltInZoomControls(true);
    setContentView(map);

显示控件!!!!!!

【问题讨论】:

    标签: android api map osmdroid


    【解决方案1】:

    它可能缺少平铺源。下面是我拥有的最小的代码示例,它将使用 osmdroid 向您显示 OSM 映射:

    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);
    
        }
    }
    /* HAVE THIS AS YOUR osm_main.xml
    ---------------------------------------------------------- XML START
    <?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"
            ></org.osmdroid.views.MapView>
    </LinearLayout>
    ---------------------------------------------------------- XML END
    Include slf4j-android-1.5.8.jar and osmdroid-android-3.0.5.jar in the build path
    (Google search for where to get them from)
    */
    

    【讨论】:

    • 谢谢,我在代码中添加了 TileSource 语句,应用程序仍然可以正常工作(没有错误,但没有地图仅显示正方形),并且 DDMS 中出现错误:
    • [2012-04-16 11:24:27 - ddms] null java.lang.NullPointerException at com.android.ddmlib.Client.sendAndConsume(Client.java:573) at com.android。 ddmlib.HandleHello.sendHELO(HandleHello.java:142) 在 com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65) 在 com.android.ddmlib.Client.getJdwpPacket(Client.java:672) 在 com.android .ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317) at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)
    • 谢谢,是的,我添加了许多其他权限,我发现人们说它们是必需的,所有权限都是:
    【解决方案2】:

    或者可能缺少清单文件中的 INTERNET(或其他)权限?

    HowToUseJar

    【讨论】:

    • 谢谢,是的,我添加了许多其他权限,我发现人们说它们是必需的,所有权限都是:
    【解决方案3】:

    你还需要添加

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    

    到您的清单。 Osmdroid 尝试缓存切片并在没有存储访问时失败。

    【讨论】:

    • rechengehirn:我已经写了所有需要的权限,包括这个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-12
    • 2019-02-26
    • 2021-06-10
    • 2012-07-11
    • 1970-01-01
    相关资源
    最近更新 更多