osmdroid displays an empty grid

非 Y 不嫁゛ 提交于 2019-12-07 01:36:54

问题


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.


回答1:


I'm pretty new to OSMdroid too but try doing this?

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

You would also need to have offline_map_activity.xml in your res/layouts:

<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>

Hope this works for you. At least this worked for my codes :)




回答2:


i tink your Device has don't SD. You have change the Cache Path

OpenStreetMapTileProviderConstants.setCachePath(this.getFilesDir().getAbsolutePath()); 


来源:https://stackoverflow.com/questions/14060389/osmdroid-displays-an-empty-grid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!