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.youkuaiyun.com/sinat_35241409/article/details/78122844?locationNum=8&fps=1