zoukankan      html  css  js  c++  java
  • 如何使用android百度地图离线地图

    1.首先把离线地图放在android工程下的assets里面。

    注意:建议离线地图下载通过百度地图APIDEMO去下载,因为到官网上下载的离线地图文件格式不一样,APIDEMO的格式是.dat,而官网上的格式是.dat_svc有可能加载不了地图.

    2.把离线地图从assets下拷贝到sd卡下

    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.初始化离线地图

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

    }
    });

  • 相关阅读:
    [转]趣题:一个n位数平均有多少个单调区间?---- From Matrix67
    2015编程之美复赛
    Codeforces Round #304 (Div. 2)
    HDU 5226
    HDU 5225
    HDU 3666
    HDU 4598
    Codeforces Round #303 (Div. 2) E
    编程之美初赛第二场AB
    2015 编程之美初赛第一场 AC题
  • 原文地址:https://www.cnblogs.com/yangqimo/p/5121722.html
Copyright © 2011-2022 走看看