在Osmdroid中打开离线磁贴

时间:2014-06-27 13:42:04

标签: java android

我正在尝试使用osmdroid开发离线地图并尝试使用从移动地图集创建者创建的mbtiles,但每次我打开它崩溃的应用程序。这是我的主要活动代码。当我使用普通的jpg文件加载图块时,它工作正常,但没有用,因为我无法绑定地图。

    package com.maptry.katgp;

    import java.io.File;
    import java.util.ArrayList;

    import org.osmdroid.DefaultResourceProxyImpl;
    import org.osmdroid.ResourceProxy;
    import org.osmdroid.api.IMapController;
    import org.osmdroid.tileprovider.IRegisterReceiver;
    import org.osmdroid.tileprovider.tilesource.XYTileSource;
    import org.osmdroid.util.BoundingBoxE6;
    import org.osmdroid.util.GeoPoint;
    import org.osmdroid.views.MapController;
    import org.osmdroid.views.MapView;
    import org.osmdroid.views.overlay.OverlayItem;

    import android.os.Bundle;
    import android.os.Environment;
    import android.app.Activity;

    public class MainActivity extends Activity implements IRegisterReceiver {
// initializing the mapview
MapView mapView;
// private MapController mapController;
 // ArrayList<OverlayItem> anotherOverlayItemArray;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // contents from the main

    setContentView(R.layout.activity_main);

    // connecting with the xml layout id

    mapView = (MapView) findViewById(R.id.mapView);

    // setting the default online tiles
    // mapnik not working so replaced by mapquest

    // for online use
    // mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);

    //adding the offline tiles using mbtiles

     DefaultResourceProxyImpl resProxy;
        resProxy = new DefaultResourceProxyImpl(this.getApplicationContext());



        File file = new File(Environment.getExternalStorageDirectory(), "maptile.mbtiles");

        MBTileProvider provider = new MBTileProvider(this, file);
        BoundedMapView mapView = new BoundedMapView(this, resProxy, provider);

        double north = 27.749177;
        double east  =  85.382652;
        double south = 27.648864;
        double west  =  85.262489;
        BoundingBoxE6 bBox = new BoundingBoxE6(north, east, south, west);

        mapView.setScrollableAreaLimit(bBox);

    /*
     * // adding the offline tiles
     * 
     * mapView.setTileSource(new XYTileSource("MapQuest",
     * ResourceProxy.string.mapquest_osm, 13, 18, 256, ".jpg", new String[]
     * { "http://otile1.mqcdn.com/tiles/1.0.0/map/",
     * "http://otile2.mqcdn.com/tiles/1.0.0/map/",
     * "http://otile3.mqcdn.com/tiles/1.0.0/map/",
     * "http://otile4.mqcdn.com/tiles/1.0.0/map/" }));
     */

    // for zooming and multitouch controls

    mapView.setBuiltInZoomControls(true);
    mapView.setMultiTouchControls(true);

    mapView.setUseDataConnection(false);
     MapController controller = mapView.getController();
        controller.setZoom(12);
        controller.animateTo(new GeoPoint(27.7, 85.32));
}

}

0 个答案:

没有答案