How to use the Android Baidu map offline map

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.