Đâ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.jar
và osmdroid-android-3.0.5.jar
trong build path. (Google tìm kiếm nơi lấy chúng từ)
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
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
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