我正在使用OSMdroid api来显示自定义图块。他们确实提供了相同的Google包装器。所以尝试显示本地服务器上的图块

这是我的代码

final MapTileProviderBasic tileProvider = new MapTileProviderBasic(getApplicationContext());
final ITileSource tileSource = new XYTileSource("SomeName", null, 3, 20, 256, ".png",
                    "http://MyServer/tiles/");
tileProvider.setTileSource(tileSource);
final GoogleTilesOverlay tilesOverlay = new GoogleTilesOverlay(tileProvider, this.getBaseContext());
 mapView.getOverlays().add(tilesOverlay);


在布局中,我通过以下方式声明了地图视图

<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="my API Key"
/>


如果我将磁贴放在sdcard下并使用以下代码,则此方法效果很好

mProvider = new MapTileProviderBasic(getApplicationContext());
mProvider.setTileSource(TileSourceFactory.FIETS_OVERLAY_NL);
mTilesOverlay = new GoogleTilesOverlay(mProvider,getParent());
mTilesOverlay.setUseDataConnection(false);
mTilesOverlay.useDataConnection();
mapView.getOverlays().add(mTilesOverlay);
mapView.invalidate();

最佳答案

这是我的xytilesource工作代码,希望它可能对某人有所帮助。

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);

        mapView.getController().setZoom(5);
        GeoPoint point = new LatLonPoint(6.83917,79.91455);
        //mapView.getController().setCenter(new GeoPoint(51500000, 5400000));
        mapView.getController().setCenter(point);
        final MapTileProviderBasic tileProvider = new MapTileProviderBasic(getApplicationContext());
        final ITileSource tileSource = new XYTileSource("SomeName", null, 3,14, 256, ".png",
                        "http://192.168.1.5/mapcache/tms/1.0.0/ms-base@GoogleMapsCompatible/");
        //mapView.setTileSource((new XYTileSource("localMapnik", Resource, 0, 18, 256, ".png",
            //  "http://tile.openstreetmap.org/")));
        tileProvider.setTileSource(tileSource);
        final TilesOverlay tilesOverlay = new TilesOverlay(tileProvider, this.getBaseContext());
        mapView.getOverlays().add(tilesOverlay);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    private static final class LatLonPoint extends GeoPoint {
        public LatLonPoint(double latitude, double longitude) {
            super((int) (latitude * 1E6), (int) (longitude * 1E6));
        }
    }


布局文件应包括

<org.osmdroid.views.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true" />

关于android - osmdroid XYTileSource在Android中不显示来自服务器的图块,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9681606/

10-13 08:56