0

I want to develope android mapping app using osmDroid mapping api with offline and online capabilites, but I couldn't find many tutorials about it, so If any one have any link to tutorials that use osmdroid mapping api offline or online. I have write a small app just to display the map from the default provider but, the application run but no map is displayed (only squers) what is wrong?? the code:

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

the controls are displayed!!!!!!

Abdalwhab Bakheet
  • 1,133
  • 2
  • 11
  • 17

3 Answers3

1

It's probably missing a tile source. Below is the smallest sample of code I have that will show you an OSM map using osmdroid:

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)
*/
NickT
  • 23,844
  • 11
  • 78
  • 121
  • thanks, I added the TileSource statement to my code and the application still work as it is (no error but no map is displayed only squares) and there is an error that appear in the DDMS that is: – Abdalwhab Bakheet Apr 16 '12 at 08:32
  • [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) at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65) at com.android.ddmlib.Client.getJdwpPacket(Client.java:672) at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317) at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263) – Abdalwhab Bakheet Apr 16 '12 at 08:33
  • thanks, yes I added many other permissions that I found people saying they are required and all the permission are: – Abdalwhab Bakheet Apr 16 '12 at 09:51
1

Or maybe missing the INTERNET (or another) permission in the manifest file?

HowToUseJar

Martin Pearman
  • 592
  • 5
  • 5
0

You also need to add

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

to your manifest. Osmdroid tries to cache the tiles and fails when there is no storage access.

pixelsucht
  • 228
  • 2
  • 8