Use of android Baidu map offline Map

Source: Internet
Author: User

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;
}

}
});

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.