【问题标题】:How to set osmdroid source using XYTileSource如何使用 XYTileSource 设置 osmdroid 源
【发布时间】:2012-11-19 19:55:30
【问题描述】:

现在我有一个代码,我使用 osmdroid 来显示我自己的离线地图,这些地图放置在 /osmdroid 我试图改变的另一个特别的事情是最小和最大缩放 ,现在我正在使用这部分代码,它什么都不显示

MapView mapview = (MapView) v.findViewById(R.id.mapview);
mapview.setUseDataConnection(false); 
final ITileSource tileSource = new XYTileSource("maps", ResourceProxy.string.mapnik, 18, 21, 256, ".png",
        "http://tile.openstreetmap.org/");

mapview.setBuiltInZoomControls(true);
mapview.setTileSource(tileSource);

但是当我设置时

setTileSource(TileSourceFactory.MAPNIK)

我的离线地图工作正常,但缩放受限

我的 XYTileSource 有什么问题吗?

提前致谢

【问题讨论】:

  • 您在 /osmdroid 中放置的图块是什么格式(我假设它实际上是 /sdcard/osmdroid/tiles?)它们是在 zip 中吗?文件? jpg?它们是否在名为“maps”的文件夹中(以匹配您的第一个参数到 XYTileSource)?

标签: android android-mapview osmdroid


【解决方案1】:

这是我在 osmdroid 中 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" />

【讨论】:

    【解决方案2】:

    确保将最大缩放级别设置为适合您的图块源的任何值:

    mapView.setMaxZoomLevel(18);
    

    【讨论】:

      猜你喜欢
      • 2020-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-28
      • 1970-01-01
      相关资源
      最近更新 更多