osmdroid displays an empty grid
Asked Answered
P

2

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.

Pyrazole answered 27/12, 2012 at 19:47 Comment(3)
Text correction: My Manifest also includes these permissions (as a child of [manifest] , after [uses-sdk] ).Pyrazole
I'm using osmdroid 3.0.7Pyrazole
probably you could help me out also @Peter,... #25460943Mousse
M
0

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

Macknair answered 28/12, 2012 at 9:57 Comment(3)
Hi! Thanks for your answer! However, the fact that a full-screen empty map grid was already being shown confirms that my problem is not layout related: setContentView(mapView) has worked correctly. Last night I realized it was something completely different: my emulator had no external storage...Pyrazole
ah i see no wonder haha. glad that you found out the problem :)Macknair
anyway, @lyk, could you help me out also? #25460943Mousse
G
-1

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

OpenStreetMapTileProviderConstants.setCachePath(this.getFilesDir().getAbsolutePath()); 
Girgenti answered 31/7, 2016 at 21:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.