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

 

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

  • 6
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
对于 Vue 中的百度地图个性化,你可以按照以下步骤进行操作: 1. 首先,在你的 Vue 项目中安装百度地图 SDK,可以通过 npm 或者 yarn 安装,例如:`npm install vue-baidu-map --save`。 2. 在你的 Vue 项目中,找到需要使用百度地图的组件,并在这个组件中引入百度地图的 SDK,例如: ```javascript import BMap from 'vue-baidu-map'; export default { components: { 'b-map': BMap.map, 'b-marker': BMap.marker } } ``` 3. 然后,你可以在组件中使用 `<b-map>` 标签来显示百度地图,例如: ```html <template> <div> <b-map :ak="YOUR_API_KEY" :center="center" :zoom="zoom" style="width: 100%; height: 400px;"> <b-marker :position="position"></b-marker> </b-map> </div> </template> ``` 其中,`YOUR_API_KEY` 是你在百度开放平台申请到的 API Key,`center` 是地图中心的经纬度坐标,`zoom` 是地图的缩放级别,`position` 是标记点的经纬度坐标。 4. 如果你想进行百度地图个性化设置,可以在组件的 `mounted()` 生命周期钩子函数中添加相关代码,例如: ```javascript mounted() { // 获取地图实例 const map = this.$refs.bMap.mapInstance; // 设置地图样式 map.setMapStyleV2({ styleJson: YOUR_CUSTOM_STYLE_JSON }); } ``` 其中,`YOUR_CUSTOM_STYLE_JSON` 是你自定义的地图样式 JSON 数据,你可以在百度地图开放平台上进行个性化样式的配置和获取。 这样,你就可以在 Vue 中进行百度地图个性化设置了。希望对你有所帮助!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值