码迷,mamicode.com
首页 > 移动开发 > 详细

如何使用android百度地图离线地图

时间:2016-01-11 18:01:23      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:

1.首先把离线地图放在android工程下的assets里面。

注意:建议离线地图下载通过百度地图APIDEMO去下载,因为到官网上下载的离线地图文件格式不一样,APIDEMO的格式是.dat,而官网上的格式是.dat_svc有可能加载不了地图.

2.把离线地图从assets下拷贝到sd卡下

public static void copy(Context context) {
try {
String filepath = Environment.getExternalStorageDirectory() + "/"
+ "BaiduMapSDK" + "/" + "vmp" + "/" + "h" + "/"
+ "xxxxx.dat";
String path = Environment.getExternalStorageDirectory() + "/"
+ "BaiduMapSDK" + "/" + "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;
}

}
});

如何使用android百度地图离线地图

标签:

原文地址:http://www.cnblogs.com/yangqimo/p/5121722.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!