百度地图个性化编辑以及使用

 

1、首先去百度的http://lbsyun.baidu.com/customv2/index.html去编辑想要的效果,然后下载它的json文件

2、设置json路径:在oncreat方法里面加入

注意:MapView.setCustomMapStylePath("/mnt/sdcard/style_json.json");此方法放在setContentView(R.layout.xxx);之前即可

方法一、MapView.setCustomMapStylePath("/mnt/sdcard/style_json.json");

              adb push 文件路径 /mnt/sdcard/

方法二:setMapCustomFile(this,PATH);

private static String PATH = "style_json.json";

 public static void setMapCustomFile(Context context, String PATH) {
        FileOutputStream out = null;
        InputStream inputStream = null;
        String moduleName = null;
        try {
            inputStream = context.getAssets()
                    .open("customConfigdir/" + PATH);
            byte[] b = new byte[inputStream.available()];
            inputStream.read(b);
            moduleName = context.getFilesDir().getAbsolutePath();
            File f = new File(moduleName + "/" + PATH);
            if (f.exists()) {
                f.delete();
            }
            f.createNewFile();
            out = new FileOutputStream(f);
            out.write(b);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (inputStream != null) {
                    inputStream.close();
                }
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        MapView.setCustomMapStylePath(moduleName + "/" + PATH);

    }

3、最重要的一点,关键代码加入的位置

参考:https://blog.csdn.net/sinat_35241409/article/details/78122844?locationNum=8&fps=1

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值