官网上介绍:地址链接
从 3D 地图 SDK V4.1.3版本开始支持自定义地图底图功能。
功能说明:支持对部分地图元素自定义颜色,包括:填充色、边框色、文字颜色。
先上图,我自己做出来的自定义地图(底图)

效果图就是以上这样,下面来说一下实现的步骤
1.高德环境集成
集成步骤请进高德开发者平台去安装步骤进行
注意:自定义的图层所需的地图是3D地图
2.布局文件

?xml version="1.0" encoding="utf-8"?>
<RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="zph.zhjx.com.chat.ui.TrackActivity"><includeandroid:id="@+id/headview1"layout="@layout/headview1"/><com.amap.api.maps.MapViewandroid:layout_below="@+id/headview1"android:id="@+id/tracked_map"android:layout_width="match_parent"android:layout_height="match_parent"android:focusable="true"></com.amap.api.maps.MapView></RelativeLayout>

3.核心代码
支持自定义的具体元素和项目,请见下表:

featureType(地图元素) geometry.fill(填充色) geometry.stroke(边框色) labels.text.fill(文字填充色) labels.text.stroke(文字边框色)
land(陆地) ✔️
water (水系) ✔️
green (绿地) ✔️
building (楼块) ✔️ ✔️
Highway (高速及城市主道路) ✔️ ✔️ ✔️ ✔️
Local (普通道路) ✔️
Railway (铁路) ✔️ ✔️
Subway (地铁) ✔️ ✔️
Boundary (行政区) ✔️ ✔️
Districtlabel (行政区文字) ✔️ ✔️
Poilabel (所有文字,除行政区&道路文字) ✔️ ✔️

根据支持自定义的具体元素和项目,我编写的JSON配置文件如下:
style_json.json
在Android studio中java目录下建立assets文件夹
将style_json.json放置到该目录下

[{"featureType":"land","elementType":"geometry.fill","stylers":{"color":"#08304B"}},{"featureType":"land","elementType":"geometry.stroke","stylers":{"color":"#021019"}},{"featureType":"land","elementType":"labels.text.fill","stylers":{"color":"#847F7F"}},{"featureType":"water","elementType":"geometry.fill","stylers":{"color":"#021019"}},{"featureType":"water","elementType":"geometry.stroke","stylers":{"color":"#08304B"}},{"featureType":"green","elementType":"geometry.fill","stylers":{"color":"#b0d3dd"}},{"featureType":"green","elementType":"geometry.stroke","stylers":{"color":"#33A1C9"}},{"featureType":"building","elementType":"geometry.fill","stylers":{"color":"#021019"}},{"featureType":"building","elementType":"geometry.stroke","stylers":{"color":""}},{"featureType":"highway","elementType":"geometry.fill","stylers":{"color":"#a6cfcf"}},{"featureType":"highway","elementType":"geometry.stroke","stylers":{"color":"#7dabb3"}},{"featureType":"highway","elementType":"labels.text.fill","stylers":{"color":"#8B4513"}},{"featureType":"highway","elementType":"labels.text.stroke","stylers":{"color":"#33A1C9"}},{"featureType":"arterial","elementType":"geometry.fill","stylers":{"color":"#a6cfcf"}},{"featureType":"arterial","elementType":"geometry.stroke","stylers":{"color":"#a6cfcf"}},{"featureType":"arterial","elementType":"labels.text.fill","stylers":{"color":"#8B4513"}},{"featureType":"arterial","elementType":"labels.text.stroke","stylers":{"color":"#8B4513"}},{"featureType":"local","elementType":"geometry.fill","stylers":{"color":"#f1f1f1"}},{"featureType":"railway","elementType":"geometry.fill","stylers":{"color":""}},{"featureType":"railway","elementType":"geometry.stroke","stylers":{"color":""}},{"featureType":"subway","elementType":"geometry.fill","stylers":{"color":"#33A1C9"}},{"featureType":"subway","elementType":"geometry.stroke","stylers":{"color":"#33A1C9"}},{"featureType":"boundary","elementType":"geometry.fill","stylers":{"color":"#33A1C9"}},{"featureType":"boundary","elementType":"geometry.stroke","stylers":{"color":"#f1f1f1"}},{"featureType":"poilabel","elementType":"labels.text.fill","stylers":{"color":"#f5f5f5"}},{"featureType":"poilabel","elementType":"labels.text.stroke","stylers":{"color":""}},{"featureType":"districtlable","elementType":"labels.text.fill","stylers":{"color":"#00affe"}},{"featureType":"districtlable","elementType":"labels.text.stroke","stylers":{"color":""}}
]

设定文件路径
官网说明如下:

1、将配置好的样式文件放入任意路径,比如”/sdcard/custom_config”
2、设定地图样式文件的路径,通过以下方法设定自定义地图样式文件的绝对路径:
百度地图的自定义底图是要求在地图初始话之前要进行样式路径设置,在高德地图中可以不这样做
我的设计是将assets中的style_json.json文件读写到手机的文件夹下面,然后设置路径为手机的路径
首先是本地文件工具类建立

public class FileUtil {private static int bufferd = 1024;private FileUtil() {}/** <!-- 在SDCard中创建与删除文件权限 --> <uses-permission* android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <!--* 往SDCard写入数据权限 --> <uses-permission* android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>*/// =================get SDCard information===================public static boolean isSdcardAvailable() {String status = Environment.getExternalStorageState();if (status.equals(Environment.MEDIA_MOUNTED)) {return true;}return false;}public static long getSDAllSizeKB() {// get path of sdcardFile path = Environment.getExternalStorageDirectory();StatFs sf = new StatFs(path.getPath());// get single block size(Byte)long blockSize = sf.getBlockSize();// 获取所有数据块数long allBlocks = sf.getBlockCount();// 返回SD卡大小return (allBlocks * blockSize) / 1024; // KB}/*** free size for normal application** @return*/public static long getSDAvalibleSizeKB() {File path = Environment.getExternalStorageDirectory();StatFs sf = new StatFs(path.getPath());long blockSize = sf.getBlockSize();long avaliableSize = sf.getAvailableBlocks();return (avaliableSize * blockSize) / 1024;// KB}// =====================File Operation==========================public static boolean isFileExist(String director) {File file = new File(Environment.getExternalStorageDirectory()+ File.separator + director);return file.exists();}/*** create multiple director** @param director* @return*/public static boolean createFile(String director) {if (isFileExist(director)) {return true;} else {File file = new File(Environment.getExternalStorageDirectory()+ File.separator + director);if (!file.mkdirs()) {return false;}return true;}}public static File writeToSDCardFile(String directory, String fileName,String content, boolean isAppend) {return writeToSDCardFile(directory, fileName, content, "", isAppend);}/**** @param directory*            (you don't need to begin with*            Environment.getExternalStorageDirectory()+File.separator)* @param fileName* @param content* @param encoding*            (UTF-8...)* @param isAppend*            : Context.MODE_APPEND* @return*/public static File writeToSDCardFile(String directory, String fileName,String content, String encoding, boolean isAppend) {// mobile SD card path +pathFile file = null;OutputStream os = null;try {if (!createFile(directory)) {return file;}file = new File(Environment.getExternalStorageDirectory()+ File.separator + directory + File.separator + fileName);os = new FileOutputStream(file, isAppend);if (encoding.equals("")) {os.write(content.getBytes());} else {os.write(content.getBytes(encoding));}os.flush();} catch (IOException e) {Log.e("FileUtil", "writeToSDCardFile:" + e.getMessage());} finally {try {if(os != null){os.close();}} catch (IOException e) {e.printStackTrace();}}return file;}/*** write data from inputstream to SDCard*/public File writeToSDCardFromInput(String directory, String fileName,InputStream input) {File file = null;OutputStream os = null;try {if (createFile(directory)) {return file;}file = new File(Environment.getExternalStorageDirectory()+ File.separator + directory + fileName);os = new FileOutputStream(file);byte[] data = new byte[bufferd];int length = -1;while ((length = input.read(data)) != -1) {os.write(data, 0, length);}// clear cacheos.flush();} catch (Exception e) {Log.e("FileUtil", "" + e.getMessage());e.printStackTrace();} finally {try {os.close();} catch (Exception e) {e.printStackTrace();}}return file;}/*** this url point to image(jpg)** @param url* @return image name*/public static String getUrlLastString(String url) {String[] str = url.split("/");int size = str.length;return str[size - 1];}
}

然后,在Activity中进行核心代码编写

package zph.zhjx.com.chat.ui;import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.TextView;import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdate;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.bumptech.glide.Glide;import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;import zph.zhjx.com.chat.R;
import zph.zhjx.com.chat.base.BaseActivity;
import zph.zhjx.com.chat.dao.People;
import zph.zhjx.com.chat.util.BitmapUtil;
import zph.zhjx.com.chat.util.DBUtil;
import zph.zhjx.com.chat.util.FileUtil;
import zph.zhjx.com.chat.view.CircleImageView;public class TrackActivity extends BaseActivity implements  AMap.OnMapLoadedListener, AMap.OnMapTouchListener, LocationSource, AMapLocationListener, View.OnClickListener, AMap.OnCameraChangeListener {private View headview;private LinearLayout back;private TextView title;private MapView mapview;private AMap aMap;private OnLocationChangedListener mListener;private AMapLocationClient mlocationClient;private AMapLocationClientOption mLocationOption;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_track);initview();initMap(savedInstanceState);}/*** 初始化地图* */private void initMap(Bundle savedInstanceState) {mapview.onCreate(savedInstanceState);if (aMap == null) {aMap = mapview.getMap();Log.i("TAG","11111");mapview.setSelected(true);setBlueMap();}aMap.setLocationSource(this);// 设置定位监听aMap.setOnMapLoadedListener(this);aMap.setOnMapTouchListener(this);aMap.setOnCameraChangeListener(this);}private void setBlueMap() {//进行JSON的文件读取然后写入到本地InputStreamReader isr = null;try {isr = new InputStreamReader(getAssets().open("style_json/style_json.json"),"UTF-8");} catch (IOException e) {e.printStackTrace();}BufferedReader br = new BufferedReader(isr);String line;StringBuilder builder = new StringBuilder();try {while((line = br.readLine()) != null){builder.append(line);}br.close();isr.close();} catch (IOException e) {e.printStackTrace();}//写入到本地目录中FileUtil.writeToSDCardFile("style_json","style.json",builder.toString(),true);//加载个性化的地图底图数据aMap.setCustomMapStylePath(Environment.getExternalStorageDirectory()+ File.separator+"style_json/style.json");//开启自定义样式aMap.setMapCustomEnable(true);aMap.getUiSettings().setMyLocationButtonEnabled(false);// 设置默认定位按钮是否显示aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false}private void initview() {mapview= (MapView) findViewById(R.id.tracked_map);headview=findViewById(R.id.headview1);back= (LinearLayout) headview.findViewById(R.id.headview_left_layout);back.setOnClickListener(this);title= (TextView) headview.findViewById(R.id.headview_left_textview);title.setText("行为轨迹"+"");}@Overridepublic void activate(OnLocationChangedListener onLocationChangedListener) {mListener = onLocationChangedListener;if (mlocationClient == null) {mlocationClient = new AMapLocationClient(this);mLocationOption = new AMapLocationClientOption();//设置定位监听mlocationClient.setLocationListener(this);//设置为高精度定位模式mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//设置多少秒去刷新位置mLocationOption.setInterval(10*1000);//设置定位参数mlocationClient.setLocationOption(mLocationOption);// 此方法为每隔固定时间会发起一次定位请求,为了减少电量消耗或网络流量消耗,// 注意设置合适的定位时间的间隔(最小间隔支持为2000ms),并且在合适时间调用stopLocation()方法来取消定位请求// 在定位结束后,在合适的生命周期调用onDestroy()方法// 在单次定位情况下,定位无论成功与否,都无需调用stopLocation()方法移除请求,定位sdk内部会移除mlocationClient.startLocation();}}@Overridepublic void deactivate() {//停止定位mListener = null;if (mlocationClient != null) {mlocationClient.stopLocation();mlocationClient.onDestroy();}mlocationClient = null;}@Overridepublic void onMapLoaded() {}@Overridepublic void onTouch(MotionEvent motionEvent) {}@Overridepublic void onLocationChanged(AMapLocation amapLocation) {if (mListener != null && amapLocation != null) {if (amapLocation != null && amapLocation.getErrorCode() == 0) {mListener.onLocationChanged(amapLocation);// 显示系统小蓝点//TODO//当定位好了以后,拿到经纬度double lat = amapLocation.getLatitude();double lng = amapLocation.getLongitude();LatLng latlng = new LatLng(lat, lng);//移动到定位处CameraUpdate movecity = CameraUpdateFactory.newLatLngZoom(latlng,9);aMap.moveCamera(movecity);deactivate();
//                showListView();} else {String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();Log.i("TAG", errText);}}else{}}/*** 方法必须重写*/@Overrideprotected void onResume() {super.onResume();mapview.onResume();}/*** 方法必须重写*/@Overrideprotected void onPause() {super.onPause();mapview.onPause();deactivate();}/*** 方法必须重写*/@Overrideprotected void onSaveInstanceState(Bundle outState) {super.onSaveInstanceState(outState);mapview.onSaveInstanceState(outState);
//        initMap(outState);}@Overrideprotected void onRestoreInstanceState(Bundle savedInstanceState) {super.onRestoreInstanceState(savedInstanceState);initMap(savedInstanceState);}@Overridepublic void onClick(View view) {switch (view.getId()){case R.id.headview_left_layout:this.finish();break;}}@Overridepublic void onCameraChange(CameraPosition cameraPosition) {if(horizontalScrollView.getVisibility()==View.VISIBLE){horizontalScrollView.setVisibility(View.INVISIBLE);}}@Overridepublic void onCameraChangeFinish(CameraPosition cameraPosition) {if(horizontalScrollView.getVisibility()==View.INVISIBLE){horizontalScrollView.setVisibility(View.VISIBLE);}Log.i("TAG","当前地图的层级:"+aMap.getCameraPosition().zoom);}
}

以上是全部内容,其中不包含在Android studio中的高德地图环境集成。

Android高德地图的自定义底图(午夜蓝主题风格地图)相关推荐

  1. Android系统开发 默认壁纸的定制 主题风格的开发及定制 DDMS 常用adb 命令 抓取Log

    Android系统开发             Android系统本身的功能在增加和完善过程中.在系统开发中如果涉及系统API的改动,则一定要慎重,系统的API的改动可能涉及Android应用程序的不 ...

  2. WebGIS——OpenLayers 3 地图叠加自定义卫星/航拍/手绘地图(任意瓦片图)

    使用OpenLayers 3 第一步 首先创建Html文件的结构,在body中放入一个Div作为地图显示的容器,调整其宽度高度使其全屏显示 html页结构如下,其中id为map的div为显示地图的容器 ...

  3. Android高德地图自定义Markers的例子

    下文为各位重点介绍关于Android高德地图自定义Markers的例子,希望这篇文章能够让各位理解到Android高德地图自定义Markers的方法. 之前的博客里说了地图的嵌入和定位,今天就说说在地 ...

  4. Android 高德地图自定义线路规划选择方案之后按照方案进行导航

    Android 高德地图自定义线路规划选择方案之后按照方案进行导航 因为我这边导航需求的问题,导致我这边不能使用高德地图官方的线路规划和导航.所以我这边线路规划和导航界面都是根据高德地图那边给的api ...

  5. Android高德地图使用自定义指南针

    UI提的bug说让移动端把 高德地图指南针图标换一下太丑,我就去高德地图的文档中找换图标的方法始终没找着,问ios他说他们有提供方法,我又研究了一下才确定高德的确只给ios提供换图标的方法了而Andr ...

  6. android高德地图中心点,高德地图中心点以及自定义infowindow

    jdfw.gif 基本效果图就是这个样子,录制这个软件不太好使,每次切换地点是点击确定变更的.接下来就看看地图上的功能是如何实现的: 实现的方式 编写自定义的infowindow 一,书写布局样式(自 ...

  7. 高德、百度地图自定义底图

    前言 项目中需要用到地图,百度地图加载自定义底图是通过切片的方式加载,而不像高德地图直接加载一张完整图片,这里瓦片加载的好处得到体现:不会因为底图文件过大导致页面加载失败或假死. 另一方面,由于自己私 ...

  8. Android高德地图自定义Mark并实现聚合效果

    Android高德地图自定义Mark并实现聚合效果 起因:公司本来项目里面用到了高德地图,然后最近老板看见别人的APP里面有个聚合的这个功能,老板:"这个效果能不能实现,我也要!" ...

  9. Android高德地图实现自定义地图样式

    现在的应用中很多地方都会用到地图这个控件,但是地图提供给我们的样式有时可能不是我们想要的样式,这时候就需要用到第三方地图的自定义样式. 本文已高德地图为例,其他地图可自定查看官方文档 官方文档地址链接 ...

最新文章

  1. error while loading shared libraries: ../../lib/libopencv_core.so
  2. 基于GPUImage的多滤镜rtmp直播推流
  3. pythonista3使用教程-pythonista3中文教程
  4. 很酷的word技巧---删除行前的空格
  5. 《零基础》MySQL 数据类型(八)
  6. Ranger-Solr审计日志安装
  7. Spring容器创建流程——总结
  8. 获取本机IP和MAC地址
  9. php排序算法算法,PHP排序算法之基数排序(Radix Sort)实例详解
  10. TreeNode.trage的使用
  11. 支付宝扫码枪收银的实现原理你了解吗?
  12. 矩阵计算与AI革命:可将计算性能提高150倍的异构计算
  13. 学计算机方面该怎样保养眼睛,电脑一族如何保护眼睛
  14. 3.28layui添加商品功能和显示所有商品功能
  15. 一个屌丝程序猿的人生(十五)
  16. 联盟 (Alliances)
  17. matlab开环调速,直流电动机开环调速MATLAB系统仿真
  18. 用R建立岭回归和lasso回归
  19. python爬空气污染实时数据_一键爬取空气质量相关指数
  20. 照片尺寸对照表[转]

热门文章

  1. 计算机专业好还是铁道运输管理好,2018年铁路最好的5个专业是什么
  2. 请问面试官?一次很有意思的调查活动
  3. Java中List 删除元素方法參考
  4. 10 个Team Leader应该具备的特质(The 10 Effective Qualities of a Team Leader)
  5. BMP图像结构及绘制
  6. RSA + AES加密原理,一线大厂主流的加密手段,流程浅析,有十分详细的测试Demo
  7. BMP格式图像文件详析
  8. 二 CH4INRULZ_v1.0.1
  9. Python二维列表【重复与循环】
  10. 集成改进的Spark书籍推荐系统的图书交易平台