0

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

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

控件显示出来了!!!!!!

4

3 回答 3

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)
*/
于 2012-04-15T14:06:06.890 回答
1

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

如何使用Jar

于 2012-04-16T07:46:01.113 回答
0

您还需要添加

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

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

于 2013-05-18T18:54:40.507 回答