7

I wanted to try out having OpenStreetMap integration by osmdroid, but I got stuck at an issue where I have no idea what is missing. The scenario is as follows:

Symptom: Map widget gets displayed but only with an empty grid.

This is in my Activity class:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MapView mapView = new MapView(this, 256);
    mapView.setTileSource(TileSourceFactory.MAPNIK);
    mapView.setClickable(true);
    mapView.setBuiltInZoomControls(true);
    setContentView(mapView);
}

(I tried selecting various TileSources with seemingly no difference)

My Manifest also includes these permissions (as a child of <manifest>, after <uses-sdk>):

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

...and my emulator is otherwise connected to the internet, eg. web browsers work.

osmdroid and slf4j are in the build path. The app compiles without a problem and generates no exceptions.

What could be wrong?

Many thanks!

SOLVED: This was caused by my emulator not having an external storage to cache map tiles.

4

2 回答 2

0

我对 OSMdroid 也很陌生,但尝试这样做吗?

setContentView(R.layout.offline_map_activity);
mapView = (MapView) findViewById(R.id.openmapview);

您还需要在 res/layouts 中有 offline_map_activity.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

    <org.osmdroid.views.MapView
        android:id="@+id/openmapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</LinearLayout>

希望这对你有用。至少这适用于我的代码:)

于 2012-12-28T09:57:11.100 回答
-1

我觉得你的设备没有 SD。您已更改缓存路径

OpenStreetMapTileProviderConstants.setCachePath(this.getFilesDir().getAbsolutePath()); 
于 2016-07-31T21:49:05.647 回答