2011-11-23 40 views
5

Tôi mới phát triển ứng dụng Android và tôi phải tạo ứng dụng Android bản đồ ngoại tuyến.Tạo bản đồ ngoại tuyến trên Android

Tôi đã sử dụng Mobile Atlas Creator để có định dạng bản đồ định dạng osmdroid .zip và tôi không biết cách thêm nó vào ứng dụng của mình.

Ai đó có thể chỉ cho tôi cách sử dụng Osmdroid trong ứng dụng của tôi không? Tôi sẽ biết ơn nếu bạn có thể cung cấp hướng dẫn từng bước.

Trả lời

4

Đây là một dự án ví dụ về minumum tuyệt đối cho Osmdroid mà tôi đã thực hiện trước đây.

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); 
    } 
} 

Có này trong thư mục 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> 

Bao gồm slf4j-android-1.5.8.jarosmdroid-android-3.0.5.jar trong build path. (Google tìm kiếm nơi lấy chúng từ)

+0

thx cho câu trả lời bạn có thể cho tôi biết cách gọi các chế độ xem được trích xuất từ ​​Mobile Atlas Creator hoặc tự động không? – Adams

+1

Tự động, chỉ cần thả tệp zip vào thư mục/sdcard/osmdroid trên điện thoại của bạn – NickT

+0

thx NickT nó đã hoạt động, bạn có thể cho tôi biết chỉ trong trình mô phỏng trong thư mục nào tôi đặt ảnh .zip thx – Adams

Các vấn đề liên quan