搜索

android 百度地图离线地图包怎么用

发布网友 发布时间:2022-02-20 01:45

我来回答

1个回答

热心网友 时间:2022-02-20 03:14

1.首先把离线地图放在android工程下的assets里面。
注意:建议离线地图下载通过百度地图APIDEMO去下载,因为到官网上下载的离线地图文件格式不一样,APIDEMO的格式是.dat,而官网上的格式是.dat_svc有可能加载不了地图.
2.把离线地图从assets下拷贝到sd卡下
public static void copy(Context context) {
try {
String filepath = Environment.getExternalStorageDirectory() + "/"
+ "BaiMapSDK" + "/" + "vmp" + "/" + "h" + "/"
+ "xxxxx.dat";
String path = Environment.getExternalStorageDirectory() + "/"
+ "BaiMapSDK" + "/" + "vmp" + "/" + "h" + "/";
File file = new File(path);
if (!file.exists()) {
file.mkdir();
}
if (!(new File(filepath)).exists()) {
new File(filepath).createNewFile();
InputStream is = context.getAssets().open(
"xxxx.dat");
FileOutputStream fos = new FileOutputStream(filepath);
byte[] buffer = new byte[8192];
int count = 0;
while ((count = is.read(buffer)) > 0) {
fos.write(buffer, 0, count);
}
fos.close();
is.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
3.初始化离线地图
private MKOfflineMap mOffline = null;
MapController mMapController;
mMapController = mMapView.getController();
mOffline = new MKOfflineMap();
mOffline.init(mMapController, new MKOfflineMapListener() {
@Override
public void onGetOfflineMapState(int type, int state) {
// TODO Auto-generated method stub
switch (type) {
case MKOfflineMap.TYPE_DOWNLOAD_UPDATE: {
}
break;
case MKOfflineMap.TYPE_NEW_OFFLINE:
break;
case MKOfflineMap.TYPE_VER_UPDATE:
break;
}
}
});
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com
Top