【问题标题】:osmdroid how to load maps from SD in progamm?osmdroid 如何在程序中从 SD 加载地图?
【发布时间】:2014-04-25 20:10:20
【问题描述】:

我有一些由 Mobile Atlas Creator 制作的 zip 地图。我已将它们放在 /osmdroid 目录中的 sd 卡上。你能帮我写这行代码来从这个目录加载这个地图吗(例如存档路径)?稍后我将创建一个对话框,用户可以在其中选择要加载的地图。但用户不应该有互联网连接。

谢谢。

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

mapview = (MapView) findViewById(R.id.mapview);
mapview.setClickable(true);
mapview.setBuiltInZoomControls(true);
mapview.setUseDataConnection(false);

}

【问题讨论】:

    标签: android osmdroid


    【解决方案1】:

    您需要设置平铺源。我假设您选择了默认的 MAPNIK。您可能还想添加一个地图控制器。

    private MapController   mMapController; // Add this
    
    @Override
    
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    mapview = (MapView) findViewById(R.id.mapview);
    mapView.setTileSource(TileSourceFactory.MAPNIK); // Add this
    mapview.setClickable(true);
    mapview.setBuiltInZoomControls(true);
    mapview.setUseDataConnection(false);
    mMapController = mapView.getController();
    mMapController.setZoom(13);
    GeoPoint gPt = new GeoPoint(yourLat, yourLong);  
    mMapController.setCenter(gPt);
    }
    

    .

    【讨论】:

    • 谢谢!我的瓦片来源是 MAPQUESTOSM,但它非常相似。现在一切正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-29
    • 1970-01-01
    • 1970-01-01
    • 2016-04-27
    • 1970-01-01
    • 2015-05-22
    相关资源
    最近更新 更多