Android Baidu map SDK offline package Import

Source: Internet
Author: User

 

 

1. Introduction to offline Map

The Baidu map SDK starts with version 2.0.0 and uses an offline map of the vector version. Please select it when downloading it. Download the offline map.

2. Initialization

 

Create a MapView before using offline map. For details about how to create a MapView, see "Hello World.

The core code for initializing an offline map is as follows:

Source code copy printing
  1. MKOfflineMap mOffline = null; // declare the variable
  2. MapController mMapController = mMapView. getController ();
  3.  
  4.  
  5. // Write it in the onCreate Function
  6. MOffline = new MKOfflineMap ();
  7. // Change the implementation method of offline.
  8. MOffline. init (mMapController, new MKOfflineMapListener (){
  9. @ Override
  10. Public void onGetOfflineMapState (int type, int state ){
  11. Switch (type ){
  12. Case MKOfflineMap. TYPE_DOWNLOAD_UPDATE:
  13. {
  14. MKOLUpdateElement update = mOffline. getUpdateInfo (state );
  15. // MText. setText (String. format (% s: % d %, update. cityName, update. ratio ));
  16. }
  17. Break;
  18. Case MKOfflineMap. TYPE_NEW_OFFLINE:
  19. Log. d (OfflineDemo, String. format (add offlinemap num: % d, state ));
  20. Break;
  21. Case MKOfflineMap. TYPE_VER_UPDATE:
  22. Log. d (OfflineDemo, String. format (new offlinemap ver ));
  23. Break;
  24. }
  25. }
  26. }
  27. ); 3. Import offline packages

    The SDK supports importing offline packages. decompress the downloaded offline packages from the official channel, and paste the vmp folder into the BaiduMapSdk folder under the root directory of the SD card. Download the offline map.

     

    Source code copy printing
    1. Int num = mOffline. scan ();
    2. // If (num! = 0)
    3. // MText. setText (String. format (% d offline packages have been installed, num ));

      If you have successfully imported the data using the above method, congratulations, you don't have to read it any more. Otherwise, please continue reading,

      If your Android phone has both internal storage and mounted SD card, you may encounter the same problems as me. Previously, I placed the downloaded offline map package on the SD card of my mobile phone. The directory structure is/mnt/sdcard/BaiduMapSdk/vmp/. At this time, it cannot be imported, because the Baidu map SDK cannot be found at all. Later, I copied the BaiduMapSdk folder to the root directory of the mobile phone's internal storage, and then re-executed it immediately.

       

      Later, I downloaded the Baidu map Android mobile app (apk ), it is found that the offline map package directory of the application is BaiduMap (I don't know why the cache directory of the offline map is BaiduMapSdk when using the SDK, but here it is BaiduMap. Is it more convenient to unify it ?), When importing an offline map package, you can select the storage location (mobile phone internal storage or SD card). When using the Baidu map sdk, there is no interface to specify the location of the offline map package, this causes the above problems when using the offline map package.

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.