1. First put the offline map in the Android project assets.
Note: Recommended offline map download through the Baidu map Apidemo to download, because the official web download offline Map file format is not the same, Apidemo format is. DAT, and the official web format is. DAT_SVC may not be able to load the map.
2. Copy the offline map from the 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 the 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
}
}
});
How to use the Android Baidu map offline map