高德地图自定义样式

首先,咱们在高德地图sdk中下载自定义地图,并在build.gradle中引用。将下载的.data文件放入assets文件夹下。关键来了,如何读取自定义地图。gradle

private void setMapCustomStyleFile(Context context) {
    String styleName = "mystyle_sdk_1507863834_0100.data";
    FileOutputStream outputStream = null;
    InputStream inputStream = null;
    String filePath = null;
    try {
        inputStream = context.getAssets().open(styleName);
        byte[] b = new byte[inputStream.available()];
        inputStream.read(b);

        filePath = context.getFilesDir().getAbsolutePath();
        File file = new File(filePath + "/" + styleName);
        if (file.exists()) {
            file.delete();
        }
        file.createNewFile();
        outputStream = new FileOutputStream(file);
        outputStream.write(b);

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (inputStream != null)
                inputStream.close();

            if (outputStream != null)
                outputStream.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    aMap.setCustomMapStylePath(filePath + "/" + styleName);

    aMap.setMapCustomEnable(true);
    aMap.showMapText(true);

}
在oncreat()方法中,
aMap = mMapView.getMap();这行代码以后便可。
 
.data文件位置以下