如何集成OSM磁贴

时间:2014-09-01 11:25:23

标签: openstreetmap

我正在开发一个应用程序,其中我想要离线地图,所以我使用osmdroid和slf4j libs.I我有使用Mobile Atlas Creator的地图图块。如何在java代码中集成这些tile?

MainActvity是:

package com.example.osmofflinemap;

import org.osmdroid.DefaultResourceProxyImpl;
import org.osmdroid.ResourceProxy;
import org.osmdroid.api.IMapController;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.tileprovider.tilesource.XYTileSource;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.ScaleBarOverlay;
import org.osmdroid.views.overlay.SimpleLocationOverlay;


import android.support.v4.app.Fragment;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;

public class MainActivity extends Activity {
    private MapView mapView;
    private MapController mapController;
    private ScaleBarOverlay mScaleBarOverlay;
    private SimpleLocationOverlay mMyLocationOverlay;
     MyItemizedOverlay myItemizedOverlay = null;
     protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
           MapView map = (MapView) findViewById(R.id.mapview);
            map.setTileSource(new XYTileSource("MapQuest",
                ResourceProxy.string.mapquest_osm, 0, 18, 256, ".jpg", new String[] {
                    "/sdcard/osmdroid/MapQuest/4/10/6",
                    "/sdcard/osmdroid/MapQuest/4/10/7",
                    "/sdcard/osmdroid/MapQuest/4/11/6",
                    "/sdcard/osmdroid/MapQuest/4/11/7"}));
            map.setBuiltInZoomControls(true);
            map.setMultiTouchControls(true);
            map.setUseDataConnection(false); //optional, but a good way to prevent loading from the network and test your zip loading. 
            IMapController mapController = map.getController();
            mapController.setZoom(4);
            GeoPoint startPoint = new GeoPoint(18.533333, 73.866667);
            mapController.setCenter(startPoint);
        }

}

0 个答案:

没有答案