使用osmDroid映射API的Android映射(android mapping using os

2019-09-16 12:57发布

我想用离线和在线capabilites osmDroid地图API来Android的下发展映射应用程序,但我无法找到很多教程有关,所以如果有任何一个有任何链接到使用osmdroid地图API脱机或联机教程。 我写一个小程序只显示从默认的供应商,而是,应用程序运行地图,地图没有显示(仅squers)什么是错的? 编码:

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

所述控件显示!!!!!!

Answer 1:

或者,也许错过了因特网(或其他)在manifest文件权限?

HowToUseJar



Answer 2:

它可能缺少瓷砖源。 下面的代码示例最小的我将使用osmdroid告诉你一个OSM地图:

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)
*/


Answer 3:

您还需要添加

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

你的清单。 Osmdroid试图缓存瓦片和在没有存储访问失败。



文章来源: android mapping using osmDroid mapping api