2011-11-23 52 views
5

我是Android應用程序開發的新手,我必須創建一個離線地圖Android應用程序。在Android上創建離線地圖

我使用Mobile Atlas Creator來獲取地圖視圖osmdroid .zip格式,我不知道如何將它添加到我的應用程序中。

有人可以告訴我如何在我的應用程序中使用Osmdroid嗎?如果您能提供分步說明,我將不勝感激。

回答

4

這是一個絕對最小的示例項目,我之前做了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); 
    } 
} 

有這個在您的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> 

包含在構建路徑slf4j-android-1.5.8.jarosmdroid-android-3.0.5.jar。 (谷歌搜索從哪裏得到它們)

+0

thx爲答案你能告訴我如何調用從移動阿特拉斯造物主提取的意見或它是自動的? – Adams

+1

這是自動的,只需將zip文件放入您的手機的文件夾/ sdcard/osmdroid – NickT

+0

thx NickT它的工作可以告訴我只是在模擬器中的哪個文件夾我把圖片.zip thx – Adams