问题
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!!!!!!
回答1:
Or maybe missing the INTERNET (or another) permission in the manifest file?
HowToUseJar
回答2:
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)
*/
回答3:
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.
来源:https://stackoverflow.com/questions/10162043/android-mapping-using-osmdroid-mapping-api