1. First, place the offline map in the assets of the android project.
Note: It is recommended that you download offline maps through Baidu map APIDEMO, because the offline map files downloaded on the official website are in different formats. The APIDEMO format is. dat, and the format on the official website is. dat_svc may not be able to load the map.
2. Copy the offline map from assets to the SD card
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. initialize offline Map
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;
}
}
});