osmdroid XYTileSource не показывает плитки с сервера в Android - PullRequest
2 голосов
/ 13 марта 2012

Я использую apis OSMdroid для отображения пользовательских плиток. Они предоставляют 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();   

1 Ответ

0 голосов
/ 01 июня 2013

Вот мой рабочий код для 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" />
...