简体   繁体   English

在Android上创建离线地图

[英]Creating an offline map on Android

I'm new to Android app development and I have to create an Offline map Android application. 我是Android应用程序开发的新手,我必须创建一个离线地图Android应用程序。

I used Mobile Atlas Creator to get the map views osmdroid .zip format, and I don't know how to add it in my app. 我使用Mobile Atlas Creator获取地图视图osmdroid .zip格式,我不知道如何在我的应用程序中添加它。

Can someone show me how to use Osmdroid in my app? 有人可以告诉我如何在我的应用程序中使用Osmdroid吗? I would be grateful if you could provide step-by-step instructions. 如果您能提供逐步说明,我将不胜感激。

This is an absolute minumum example project for Osmdroid which I made sometime ago. 这是我前一段时间制作的Osmdroid绝对最小的示例项目。

package osmdemo.demo;

import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;

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

// This is all you need to display an OSM map using osmdroid
public class OsmdroidDemoMap extends Activity {

    private MapView         mMapView;
    private MapController   mMapController;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.osm_main);
        mMapView = (MapView) findViewById(R.id.mapview);
        mMapView.setTileSource(TileSourceFactory.MAPNIK);
        mMapView.setBuiltInZoomControls(true);
        mMapController = mMapView.getController();
        mMapController.setZoom(13);
        GeoPoint gPt = new GeoPoint(51500000, -150000);
        //Centre map near to Hyde Park Corner, London
        mMapController.setCenter(gPt);
    }
}

Have this in your osm_main.xml osm_main.xml有这个

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <org.osmdroid.views.MapView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:id="@+id/mapview" />
</LinearLayout>

Include slf4j-android-1.5.8.jar and osmdroid-android-3.0.5.jar in the build path. 在构建路径中包含slf4j-android-1.5.8.jarosmdroid-android-3.0.5.jar (Google search for where to get them from) (Google搜索从哪里获取)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM