日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android osm 离线地图,android openStreetMap 离线地图

發布時間:2024/1/1 编程问答 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android osm 离线地图,android openStreetMap 离线地图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一 Mobile_Atlas_Creator_1.8的使用

png1.png

1.Map source

選擇Microsoft Maps China(因為其他地圖源都不怎么行,沒開APN的問題?)

2.zoom levels

選擇你需要的發大比例,可以多選,放數值越大下載的地圖瓦塊也多,離線地圖包就越大。自行選擇。

3.地圖的選擇

選擇所要制作離線地圖的區域,可以通過長按鼠標左鍵并且拖拽選擇,也可以在軟件左側-坐標信息填寫經緯度范圍去選擇,選擇好之后記得點擊“選擇該區域”按鈕;

,

4點擊Atlas Content下的Mapnik,確定好自己勾選的zoom levels,點擊Add selection,再點擊create atlas 開始下載

png2.png

建議修改文件名稱為Mapnik 如圖:

png3.png

好了,離線地圖就下載好了。地圖路徑:Mobile_Atlas_Creator_1.8\Mobile_Atlas_Creator_1.8\atlases

二 離線地圖的加載

權限

提示:編譯版本為23或以上版本,要注意動態獲取讀寫存儲空間權限,否則地圖可能不顯示

布局:

android:id="@+id/mapView"

android:layout_width="match_parent"

android:layout_height="match_parent"

/>

讀取離線地圖方法

private void readMap(File f) {

//f是離線地圖的壓縮包(Mapnik .zip的路徑獲取的file)

if (f.exists()) {

File[] list = f.listFiles();

if (list != null) {

for (int i = 0; i < list.length; i++) {

if (list[i].isDirectory()) {

continue;

}

String name = list[i].getName().toLowerCase();

if (!name.contains(".")) {

continue; // 跳過沒有擴展名的文件

}

name = name.substring(name.lastIndexOf(".") + 1);

if (name.length() == 0) {

continue;

}

if (ArchiveFileFactory.isFileExtensionRegistered(name)) {

try {

// ok found a file we support and have a driver for

// the format, for this demo, we'll just use the

// first one

// 離線創建的provider瓦,它只會做

// 離線文件archives

// 一次使用的第一個文件

OfflineTileProvider tileProvider = new OfflineTileProvider(

new SimpleRegisterReceiver(getActivity()),

new File[] { list[i] });

// tell osmdroid to use that provider instead of the

// default rig which is (asserts, cache,

// files/archives, online

mMapView.setTileProvider(tileProvider);

// this bit enables us to find out what tiles

// sources are available. note, that this action may

// take some time to run

// and should be ran asynchronously. we've put it

// inline for simplicity

String source = "";

IArchiveFile[] archives = tileProvider

.getArchives();

if (archives.length > 0) {

// cheating a bit here, get the first archive

// file and ask for the tile sources names it

// contains

Set tileSources = archives[0]

.getTileSources();

// presumably, this would be a great place to

// tell your users which tiles sources are

// available

if (!tileSources.isEmpty()) {

// ok good, we found at least one tile

// source, create a basic file based tile

// source using that name

// and set it. If we don't set it, osmdroid

// will attempt to use the default source,

// which is "MAPNIK",

// which probably won't match your offline

// tile source, unless it's MAPNIK

source = tileSources.iterator().next();

this.mMapView

.setTileSource(FileBasedTileSource

.getSource(source));

} else {

this.mMapView

.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);

}

} else {

this.mMapView

.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);

}

// Toast.makeText(

// this,

// "Using " + list[i].getAbsolutePath() + " "

// + source, Toast.LENGTH_SHORT)

// .show();

this.mMapView.invalidate();

return;

} catch (Exception ex) {

ex.printStackTrace();

}

}

}

}

// Toast.makeText(

// this,

// f.getAbsolutePath()

// + " did not have any files I can open! Try using MOBAC",

// Toast.LENGTH_SHORT).show();

} else {

// Toast.makeText(this, f.getAbsolutePath() + " dir not found!",

// Toast.LENGTH_SHORT).show();

}

}

地圖初始化

private MapView mMapView;

private IMapController mapControl;

public View CreateView(LayoutInflater inflater, ViewGroup container,

Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.fragment_national_weather,

container, false);

mMapView = (MapView) view.findViewById(R.id.mapView);

mMapView.setUseDataConnection(false); // 設置取消通過網絡加載

readMap(China);//加載離線地圖

mMapView.setClickable(true);//設置可點擊

mMapView.setBuiltInZoomControls(true);//放大縮小功能開啟

mapControl = mMapView.getController();//獲得控制器

mMapView.setMultiTouchControls(true);// 設置多指觸控可用

mMapView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);// 關閉硬件加速(繪制軌跡時需要)

mMapView.getOverlays().clear();//清空地圖上的標記

GeoPoint cententGeo=new GeoPoint(37.926868, 112.543945);

mapControl.setCenter(cententGeo);//設置地圖中心點,注意中心點請根據自己截取的地圖,獲取其中點的經緯度

mMapView.setMinZoomLevel(6); //設置最小放大級別

mMapView.setMaxZoomLevel(7);//設置最大放大級別

mapControl.setZoom(6);//設置縮放級別

}

//添加maker

private void addPointe(GeoPoint dian, Drawable draw) {

Marker marker = new Marker(mMapView);

marker.setIcon(draw);// 設置圖標

marker.setPosition(dian);// 設置位置

marker.setAnchor(0.5f, 1f);// 設置偏移量

// marker.setTitle("我是Titile");//設置標題

// marker.setSubDescription("我是SubDescription");//設置說明

mMapView.getOverlays().add(marker);// 添加marker到MapView

}

總結

以上是生活随笔為你收集整理的android osm 离线地图,android openStreetMap 离线地图的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。