关于android百度地图离线地图的使用
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;
}
}
});
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。