1252 lines
49 KiB
Markdown
1252 lines
49 KiB
Markdown
# SDK API
|
||
[toc]
|
||
|
||
## 一.地图相关
|
||
|
||
### 1.显示地图
|
||
|
||
|
||
#### 1.1添加依赖
|
||
```
|
||
implementation 'com.zhidaoauto.machine:map:1.0.0-vr-8.5.79'
|
||
或者引入相关aar包 mapmodule-release-1.0.0_1.aar
|
||
|
||
|
||
//本库依赖于koltin以及协程进行开发,请引入以下 版本请参考ext.kotlin_version = '1.3.50' ext.kotlinCoroutinesVersion = '1.3.3'
|
||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${kotlinCoroutinesVersion}"
|
||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${kotlinCoroutinesVersion}"
|
||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||
implementation 'com.alibaba:fastjson:1.2.73'
|
||
implementation 'com.amap.api:location:5.3.1'
|
||
```
|
||
|
||
#### 1.2申明权限
|
||
|
||
使用地图SDK之前,需要在 AndroidManifest.xml 文件中进行相关权限设置,确保地图功能可以正常使用。
|
||
```
|
||
|
||
<!--允许程序打开网络套接字-->
|
||
<uses-permission android:name="android.permission.INTERNET" />
|
||
<!--允许程序设置内置sd卡的写权限-->
|
||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||
<!--允许程序获取网络状态-->
|
||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||
<!--允许程序访问WiFi网络信息-->
|
||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||
<!--允许程序读写手机状态和身份-->
|
||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||
<!--允许程序访问CellID或WiFi热点来获取粗略的位置-->
|
||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||
```
|
||
|
||
#### 1.3初始化
|
||
|
||
(1)、初始化 默认配置在Application的onCreate()中添加
|
||
```
|
||
val mapParams = MapParams.init()
|
||
.setCoordinateType(MapParams.COORDINATETYPE_GCJ02)
|
||
.setPerspectiveMode(MapParams.MAP_PERSPECTIVE_2D)
|
||
.setStyleMode(MapParams.MAP_STYLE_NIGHT)
|
||
.setAutoLocation(true) //是否开启定位 true 开启 false 不开启
|
||
.setDataFileSource(0) //设置获取文件是从本地还是redis 0 redis 1本地
|
||
.setDataRedisFileSource(0) //设置redis是开发环境还是正式环境 0 正式 1 测试
|
||
.setQzoneFilterArray(tileFilter)
|
||
.setCarPosition(3f)
|
||
MapAutoApi.init(this,mapParams)
|
||
```
|
||
(2)、地图配置相关参数MapParams
|
||
|
||
名称 | 说明
|
||
---- | -----
|
||
setDebugMode(debug: Boolean): MapParams | 设置是否为deBug模式
|
||
setCoordinateType(coordinateType: Int): MapParams | 设置坐标类型 GPS(WGS84) 0 ;GCJ-02(高德) 1; BD09(百度) 2;
|
||
setStyleDir(stylePath: String): MapParams | 设置地图样式路径
|
||
setCachePath(cachePath: String): MapParams | 设置地图缓存路径
|
||
setHdmapPath(hdmapPath: String): MapParams | 设置高精数据路径
|
||
setZoom(zoom: Int): MapParams | 设置地图默认显示层级
|
||
setPointToCenter(offsetX: Float, offsetY: Float): MapParams | 设置地图中心偏移 参数去做 0-1
|
||
setStyleMode(styleMode: Int): MapParams | 设置地图模式 type MapAutoApi.MAP_STYLE_DAY 日间模式 MapAutoApi.MAP_STYLE_NIGHT 夜间模式 MapAutoApi.MAP_STYLE_VR VR模式
|
||
setPerspectiveMode(perspectiveMode: Int): MapParams | 设置地图视图模式 MapParams.MAP_PERSPECTIVE_2D-- 2D模式, MapParams.MAP_PERSPECTIVE_3D-- 3D模式 MapParams.MAP_PERSPECTIVE_UP_CAR-- 车头向上模式 MapParams.MAP_PERSPECTIVE_UP_NORTH-- 正北向上模式
|
||
setAutoSwitch(isAutoSwitch: Boolean): MapParams | 设置是否自动切换日夜模式
|
||
setAutoLocation(isAutoLocation: Boolean): MapParams | 设置是否自动定位
|
||
setDataFileSource(dataFileSource: Int): MapParams | 设置获取数据方式 1,本地文件。非1,redis获取
|
||
setQzoneFilterArray(filter: IntArray): MapParams | 设置可选择数据区域加载功能 (北京 1101 衡阳 4304 武汉 4201 鄂州 4207)
|
||
setCarPosition(offset: Float): MapParams | 设置自车位置 offset 1.0-6.0, <4.0车向上,>4.0车向下
|
||
|
||
(3)、初始化地图容器
|
||
布局添加
|
||
```
|
||
|
||
<com.zhidaoauto.map.sdk.open.view.MapAutoView
|
||
android:id="@+id/mapAutoView"
|
||
android:layout_width="match_parent"
|
||
android:layout_height="match_parent" />
|
||
```
|
||
|
||
#### 1.4周期方法
|
||
```
|
||
|
||
class StandardActivity: Activity() {
|
||
|
||
override fun onCreate(savedInstanceState: Bundle?) {
|
||
super.onCreate(savedInstanceState)
|
||
setContentView(R.layout.layout_main)
|
||
mapAutoView.onCreate(savedInstanceState)
|
||
initView()
|
||
}
|
||
|
||
private fun initView() {
|
||
}
|
||
|
||
|
||
override fun onResume() {
|
||
super.onResume()
|
||
mapAutoView.onResume()
|
||
}
|
||
|
||
override fun onPause() {
|
||
super.onPause()
|
||
mapAutoView.onPause()
|
||
}
|
||
|
||
override fun onDestroy() {
|
||
super.onDestroy()
|
||
mapAutoView.onDestroy()
|
||
}
|
||
}
|
||
```
|
||
#### 1.5地图事件
|
||
|
||
(1)、地图点击事件
|
||
|
||
```
|
||
实现接口OnMapClickListener
|
||
interface OnMapClickListener {
|
||
fun onMapClick(lonLatPoint: LonLatPoint) //lonLatPoint 点击位置坐标
|
||
}
|
||
设置监听
|
||
mapAutoView.setOnMapClickListener(onMapClickListener:OnMapClickListener)
|
||
```
|
||
|
||
(2)、地图触摸事件
|
||
|
||
```
|
||
实现接口OnMapTouchListener
|
||
interface OnMapTouchListener {
|
||
fun onTouch(event: MotionEvent?):Boolean
|
||
}
|
||
设置监听
|
||
mapAutoView.setOnMapTouchListener(onMapTouchListener:OnMapTouchListener)
|
||
```
|
||
(3)、地图加载完成事件
|
||
|
||
```
|
||
实现接口OnMapLoadedListener
|
||
interface OnMapLoadedListener {
|
||
fun onMapLoaded() //地图加载完成
|
||
fun onRoadLoaded(roadInfo:String?)//道路加载完成 roadInfo 道路信息
|
||
}
|
||
设置监听
|
||
mapAutoView.setOnMapLoadedListener(onMapLoadedListener: OnMapLoadedListener?)
|
||
```
|
||
(4)、地图状态变化事件
|
||
|
||
```
|
||
实现接口OnCameraChangeListener
|
||
interface OnCameraChangeListener {
|
||
//type: 变化类型 MapAutoApi.LISTENER_TYPE_ZOOM 缩放 MapAutoApi.LISTENER_TYPE_ROTATE 旋转 MapAutoApi.LISTENER_TYPE_3D 视角 MapAutoApi.LISTENER_TYPE_FOCUS 移动 value: 具体值
|
||
fun onCameraChange(type:Int,value:Int)
|
||
//地图状态变化结束回调 position: 位置信息
|
||
fun onCameraChangeFinish(position: CameraPosition?)
|
||
}
|
||
设置监听
|
||
mapAutoView.setOnCameraChangeListener(onCameraChangeListener: OnCameraChangeListener?)
|
||
```
|
||
(5)、地图截屏事件
|
||
|
||
```
|
||
实现接口MapScreenListener
|
||
interface MapScreenListener : OnMapScreenShotListener {
|
||
override fun onMapScreenShot(bitmap: Bitmap?) //bitmap 截屏图片
|
||
}
|
||
设置监听
|
||
mapAutoView.registerScreenListener(mapScreenListener: OnMapScreenShotListener?)
|
||
```
|
||
(6)、地图模式监听事件
|
||
|
||
```
|
||
实现接口OnMapStyleListener
|
||
interface OnMapStyleListener {
|
||
//type MapAutoApi.MAP_STYLE_DAY 日间模式 MapAutoApi.MAP_STYLE_NIGHT 夜间模式 MapAutoApi.MAP_STYLE_VR VR模式
|
||
fun onChangeMapStyle(style: Int)
|
||
}
|
||
设置监听
|
||
mapAutoView.setOnMapStyleListener(onMapStyleListener: OnMapStyleListener?)
|
||
```
|
||
|
||
(7)、地图视角切换监听事件
|
||
|
||
```
|
||
实现接口OnMapViewVisualAngleChangeListener
|
||
interface OnMapViewVisualAngleChangeListener {
|
||
//type MapAutoApi.MAP_STYLE_VR_ANGLE_NEAR 近视角 MapAutoApi.MAP_STYLE_VR_ANGLE_MIDDLE 中视角 MapAutoApi.MAP_STYLE_VR_ANGLE_FAR 远视角
|
||
fun onMapViewVisualAngleChange(type: Int)
|
||
}
|
||
设置监听
|
||
mapAutoView.setOnMapViewVisualAngleChangeListener(onMapViewVisualAngleChangeListener: OnMapViewVisualAngleChangeListener?)
|
||
```
|
||
|
||
(8)、地图滑动监听事件
|
||
|
||
```
|
||
实现接口OnScrollListener
|
||
interface OnScrollListener{
|
||
fun scrollBy(x:Double,y:Double) //x: X轴滑动距离 y:Y轴滑动距离
|
||
}
|
||
设置监听
|
||
mapAutoView.registerScrollListener(lis: OnScrollListener?)
|
||
```
|
||
|
||
(9)、地图渲染监听事件
|
||
|
||
```
|
||
实现接口OnRenderListener
|
||
interface OnRenderListener {
|
||
fun renderTime(time:Long) //time 渲染时间
|
||
}
|
||
设置监听
|
||
mapAutoView.registerRenderListener(renderListener: OnRenderListener?)
|
||
```
|
||
|
||
### 2.定位相关
|
||
|
||
(1)、定位
|
||
```
|
||
var locationClient: LocationClient = LocationClient(this)
|
||
|
||
|
||
fun startLocation() {
|
||
locationClient?.registerListener(this)
|
||
locationClient?.start()
|
||
}
|
||
|
||
fun unRegisterListener() {
|
||
locationClient?.unRegisterListener(this)
|
||
}
|
||
```
|
||
|
||
(2)、实现LocationClient.LocationListener接口处理返回数据
|
||
```
|
||
fun onLocationChanged(location: Location){}
|
||
|
||
```
|
||
(3)、使用外部数据相关
|
||
```
|
||
mapAutoView.getLocationClient().setIsUseExtraGPSData(true)//设置是否外部数据
|
||
mapAutoView.getLocationClient().setExtraSelfGPSData(currentLocation.copy())//使用外部数据 参数 外部数据坐标
|
||
```
|
||
使用外部数据模拟移动相关示例
|
||
```
|
||
mapAutoView.getLocationClient().setIsUseExtraGPSData(true)
|
||
mapAutoView.getLocationClient().rtkEnable(true)
|
||
mTrackJob?.cancel()
|
||
try {
|
||
inputStream?.close()
|
||
} catch (e: Exception) {
|
||
|
||
}
|
||
mTrackJob = GlobalScope.launch(Dispatchers.Default) {
|
||
while (loopFlag) {
|
||
mapAutoView.getLocationClient().reset()
|
||
var inputreader: InputStreamReader? = null
|
||
var buffreader: BufferedReader? = null
|
||
try {
|
||
inputStream
|
||
= this@VrActivity.getAssets().open("heng_20210722.csv")
|
||
inputreader = InputStreamReader(inputStream)
|
||
buffreader = BufferedReader(inputreader)
|
||
var line: String? = null
|
||
var duration: Long = 3
|
||
var lastTime: Long = 0
|
||
var currentLocation :MogoLocation? = null
|
||
var location = MogoLocation()
|
||
//分行读取
|
||
while (buffreader != null && buffreader?.readLine()
|
||
.also({line = it }) != null) {
|
||
if (!stepFlag) {
|
||
loopFlag = false
|
||
break
|
||
}
|
||
val lines = line!!.split(",")
|
||
location.provider = "GPS_SELF"
|
||
val time = lines[0].trim().toLong()
|
||
location.lon = lines[1].trim().toDouble()
|
||
location.lat = lines[2].trim().toDouble()
|
||
location.distance = lines[6].trim().toDouble()
|
||
location.speed = 1f
|
||
var angle = lines[4].trim().toFloat()
|
||
if(currentLocation == null){
|
||
currentLocation = location
|
||
lastTime = time
|
||
continue
|
||
}else{
|
||
currentLocation.duration =
|
||
currentLocation.duration+ time - lastTime
|
||
lastTime = time
|
||
if(currentLocation.duration <= 10){
|
||
continue
|
||
}
|
||
}
|
||
if(currentLocation.duration > 1000){
|
||
currentLocation.duration= 300
|
||
}
|
||
//初始值
|
||
var heading = angle
|
||
if (heading == -100f) {
|
||
if (mLastHeading != 400f) {
|
||
heading = mLastHeading
|
||
} else {
|
||
heading = 0f
|
||
}
|
||
}
|
||
currentLocation.heading = heading
|
||
step++
|
||
if (step >= 1) {
|
||
step = 0
|
||
now = System.currentTimeMillis()
|
||
start = now
|
||
var realDuration = currentLocation.duration
|
||
currentLocation.duration = realDuration
|
||
mapAutoView.getLocationClient()
|
||
.setExtraSelfGPSData(currentLocation.copy())
|
||
delay(realDuration)
|
||
location.duration = 0
|
||
}
|
||
currentLocation.lon = location.lon
|
||
currentLocation.lat = location.lat
|
||
currentLocation.heading = location.heading
|
||
currentLocation.distance = location.distance
|
||
currentLocation.duration = 0
|
||
}
|
||
} catch (e: IOException) {
|
||
e.printStackTrace()
|
||
} finally {
|
||
buffreader?.close()
|
||
inputreader?.close()
|
||
inputStream?.close()
|
||
}
|
||
}
|
||
}
|
||
```
|
||
|
||
### 3.自车相关
|
||
|
||
(1)、获取自车锚点
|
||
```
|
||
mapAutoView?.getMapAutoViewHelper()?.getMyLocationStyle()?
|
||
.getSelfMarker()
|
||
```
|
||
(2)、设置自车锚点图片或模型
|
||
```
|
||
mapAutoView?.getMapAutoViewHelper()?.getMyLocationStyle()?
|
||
.myLocationIcon(R.raw.other_car, true)//第一个参数: 自车图片或模型 第二个参数:true : 3D模型 false: 2D
|
||
```
|
||
(3)、显示自车
|
||
```
|
||
mapAutoView?.getMapAutoViewHelper()?.getMyLocationStyle()?.showCar()
|
||
```
|
||
(4)、隐藏自车
|
||
```
|
||
mapAutoView?.getMapAutoViewHelper()?.getMyLocationStyle()?.hideCar()
|
||
```
|
||
(5)、设置自车角度
|
||
```
|
||
mapAutoView?.getMapAutoViewHelper()?.getMyLocationStyle()?
|
||
.setRotateAngle(angle: Float)//angle: 角度
|
||
```
|
||
|
||
|
||
### 4.地图样式相关
|
||
|
||
(1)、获取当前图层类型
|
||
```
|
||
mapAutoView.getMapAutoViewHelper()?.getMapStyle()
|
||
```
|
||
图层 | Value
|
||
-------- | --------
|
||
日间模式 | MapAutoApi.MAP_STYLE_DAY
|
||
夜间模式 | MapAutoApi.MAP_STYLE_NIGHT
|
||
VR模式 | MapAutoApi.MAP_STYLE_VR
|
||
(2)、设置图层类型
|
||
|
||
```
|
||
mapAutoView.getMapAutoViewHelper()?
|
||
.setMapStyle(MapAutoApi.MAP_STYLE_NIGHT)
|
||
```
|
||
(3)、切换地图视角
|
||
```
|
||
setMapViewVisualAngle(type: Int) //type : MapAutoApi.MAP_STYLE_VR_ANGLE_NEAR 近视角 MapAutoApi.MAP_STYLE_VR_ANGLE_MIDDLE 中视角 MapAutoApi.MAP_STYLE_VR_ANGLE_FAR 远视角
|
||
|
||
示例代码
|
||
mapAutoView.getMapAutoViewHelper()?.setMapViewVisualAngle(0)
|
||
|
||
切换近景视角
|
||
mapAutoView.getMapAutoViewHelper()?
|
||
.setNearViewAnglePosition(lonLatPoint: LonLatPoint, isGps: Boolean) //lonLatPoint: 近视角显示的位置坐标 isGPS true gps坐标 false 高德坐标
|
||
```
|
||
详细参考以下代码
|
||
```
|
||
var mMapStyle = mapAutoView.getMapAutoViewHelper()?.getMapStyle()
|
||
when (mMapStyle){
|
||
MapAutoApi.MAP_STYLE_DAY ->{
|
||
mapAutoView.getMapAutoViewHelper()?
|
||
.setMapStyle(MapAutoApi.MAP_STYLE_NIGHT)
|
||
btn_style.setText("夜间模式")
|
||
}
|
||
MapAutoApi.MAP_STYLE_NIGHT ->{
|
||
mapAutoView.getMapAutoViewHelper()?
|
||
.setMapStyle(MapAutoApi.MAP_STYLE_DAY)
|
||
btn_style.setText("日间模式")
|
||
}
|
||
}
|
||
```
|
||
(4)、自定义地图模版改变底图颜色和样式,实现可视化的编辑和控制显示地图元素。
|
||
|
||
实现代码如下
|
||
```
|
||
MapParams.init().setStyleDir("/sdcard/shmdata_asset/style")//参数 样式文件路径
|
||
```
|
||
|
||
## 二.地图交互相关
|
||
|
||
### 1.控件交互
|
||
|
||
(1)、定位按钮
|
||
```
|
||
//显示
|
||
mapAutoView.getMapAutoViewHelper()?.showLocation()
|
||
//隐藏
|
||
mapAutoView.getMapAutoViewHelper()?.hiddenLocation()
|
||
//位置
|
||
mapAutoView.getMapAutoViewHelper()?.setLocationPosition(Gravity.TOP, 10, 0, 10, 10)//第一个参数:按钮显示位置 第二个参数:按钮显示距顶部距离 第三个参数:按钮显示距底部距离 第四个参数:按钮显示距左距离 第五个参数: 按钮显示距右距离
|
||
```
|
||
(2)、缩放按钮
|
||
```
|
||
//显示
|
||
mapAutoView.getMapAutoViewHelper()?.showZoom()
|
||
//隐藏
|
||
mapAutoView.getMapAutoViewHelper()?.hiddenZoom()
|
||
//位置
|
||
mapAutoView.getMapAutoViewHelper()?.setZoomPosition(Gravity.TOP, 10, 0, 10, 10)//参数同定位按钮
|
||
```
|
||
(3)、比例尺
|
||
```
|
||
//显示
|
||
mapAutoView.getMapAutoViewHelper()?.showScale()
|
||
//隐藏
|
||
mapAutoView.getMapAutoViewHelper()?.hiddenScale()
|
||
//位置
|
||
mapAutoView.getMapAutoViewHelper()?.setScalePosition(Gravity.TOP, 10, 0, 10, 10)//参数同定位按钮
|
||
```
|
||
(4)、Logo
|
||
```
|
||
//显示
|
||
mapAutoView.getMapAutoViewHelper()?.showLogo()
|
||
//隐藏
|
||
mapAutoView.getMapAutoViewHelper()?.hiddenLogo()
|
||
//位置
|
||
mapAutoView.getMapAutoViewHelper()?.setLogoPosition(Gravity.TOP, 10, 0, 10, 10)//参数同定位按钮
|
||
```
|
||
(5)、指南针
|
||
```
|
||
//显示
|
||
mapAutoView.getMapAutoViewHelper()?.showDirection()
|
||
//隐藏
|
||
mapAutoView.getMapAutoViewHelper()?.hiddenDirection()
|
||
//位置
|
||
mapAutoView.getMapAutoViewHelper()?.setDirectionPosition(Gravity.TOP, 10, 0, 10, 10)//参数同定位按钮
|
||
```
|
||
|
||
### 2.手势交互
|
||
|
||
(1)、缩放手势开关
|
||
```
|
||
mapAutoView.getMapAutoViewHelper()?.setZoomGesturesEnabled(isCanZoom)//设置手势是否可以缩放 isCanZoom true 可缩放 false 不可缩放
|
||
mapAutoView.getMapAutoViewHelper()?.isZoomGesturesEnabled()// 获取开关状态 返回值 true 可缩放 false 不可缩放
|
||
```
|
||
|
||
(2)、滑动手势开关
|
||
```
|
||
mapAutoView.getMapAutoViewHelper()?.setScrollGesturesEnabled(isCanScroll)//设置手势是否可以滑动 isCanScroll true 可滑动 false 不可滑动
|
||
mapAutoView.getMapAutoViewHelper()?.isScrollGesturesEnabled()//获取是否可滑动 返回值 true 可滑动 false 不可滑动
|
||
```
|
||
|
||
(3)、旋转手势开关
|
||
```
|
||
mapAutoView.getMapAutoViewHelper()?.setRotateGesturesEnabled(isCanRotate)//设置手势是否可以旋转 isCanRotate true 可旋转 false 不可旋转
|
||
mapAutoView.getMapAutoViewHelper()?.isRotateGesturesEnabled()//获取是否可以旋转 返回值 true 可旋转 false 不可旋转
|
||
```
|
||
|
||
(4)、倾斜手势开关
|
||
```
|
||
mapAutoView.getMapAutoViewHelper()?.setTiltGesturesEnabled(isCanTitl)//设置手势是否可以斜滑 isCanTitl true 可斜滑 false 不可斜滑
|
||
mapAutoView.getMapAutoViewHelper()?.isTiltGesturesEnabled()//获取是否可以斜滑 返回值 true 可斜滑 false 不可斜滑
|
||
```
|
||
|
||
(5)、手势总开关
|
||
```
|
||
mapAutoView.getMapAutoViewHelper()?.setAllGesturesEnabled(isCanTitl)//参数 true 所有手势都可以 false 所有手势都不可以
|
||
```
|
||
|
||
|
||
### 3.调用方法交互
|
||
|
||
地图交互的核心方法均依赖 MapAutoViewHelper类 使用mapAutoView.getMapAutoViewHelper()获取
|
||
|
||
名称 | 说明
|
||
---- | -----
|
||
setRenderFrequency(enableSync: Boolean,renderTimePer:Int) | 设置地图同步渲染事件 enableSync: 是否同步, renderTimePer:同步时间
|
||
setLocation(lonLatPoint: LonLatPoint) | 设置当前定位点 非锁车模式有效 即setLockMode(false) lonLatPoint:坐标
|
||
setCenter(lonLatPoint: LonLatPoint) | 设置当前中心点 非锁车模式有效 即setLockMode(false) lonLatPoint:坐标
|
||
getCenter(): LonLatPoint | 获取当前中心点 返回值当前中心点
|
||
getLastKnownLocation(): MogoLocation | 获取最后一次定位点 返回最后一次定位点
|
||
setOffset(left: Int, top: Int) | 设置地图中心偏移量 left: 屏幕横X轴偏移量 top:屏幕Y轴偏移量
|
||
zoomIn() | 地图放大
|
||
zoomOut() | 地图缩小
|
||
zoomIn(cx: Float, cy: Float) | 地图放大 cx:横向比例 cy: 竖向比例
|
||
getZoom(): Int | 获取地图当前缩放值
|
||
setZoom(zoomIndex: Int) | 设置地图缩放值
|
||
setMapViewAngle(angle: Float) | 设置地图视角(带动画) angle:地图视角
|
||
setVrEyeHeight(eyeHeight: Float) | 设置地图视点高度(带动画) eyeHeight: 视点高度
|
||
animateTo(lon: Double,lat: Double,rotateAngle: Float, isGPS: Boolean) | 设置地图移动(带动画) lon, lat地图移动到的位置 rotateAngel 地图移动结束的旋转角度 isGps 是否是GPS坐标
|
||
animateTo(lon: Double,lat: Double, zoom: Float,rotateAngle: Float,overlookAngle: Float,eyeHeight: Float,mDuration:Int,isGPS: Boolean) | 设置地图移动 地图移动结束的缩放值, overlookAngle 地图移动结束的视角,eyeHeight 地图移动结束的视点高度, mDuration 移动动画时长, 其余参数同上
|
||
animateTo(lon: Double,lat: Double,rotateAngle: Float, mDuration:Int, isGPS: Boolean) | 设置地图移动 同上
|
||
animateTo(zoom: Float, overlookAngle: Float, eyeHeight: Float, mDuration:Int) | 设置地图移动 同上
|
||
setMapDAngle(angle: Float) | 设置地图视角 angle:地图视角
|
||
getMapDAngle(): Float | 获取地图视角 返回地图视角
|
||
setMapViewRotateAngle(rotateAngle: Float) | 设置地图旋转角度(带动画) rotateAngle:旋转角度
|
||
setMapViewRotation(rotation: Float) | 设置地图旋转角度 rotation:旋转角度
|
||
getMapViewRotation(): Float | 获取地图旋转角度 返回值 旋转角度
|
||
setMapViewPerspective(mapPerspective: Int) | 设置地图视图模式 MapAutoApi.MAP_PERSPECTIVE_2D 2D模式, MapAutoApi.MAP_PERSPECTIVE_3D 3D模式 MapAutoApi.MAP_PERSPECTIVE_UP_CAR 车头向上模式 MapAutoApi.MAP_PERSPECTIVE_UP_NORTH 正北向上模式
|
||
getMapViewPerspective(): Float | 获取地图视图模式 返回值 地图试图模式 1: 2D模式 2: 3D模式 3:车头向上 4:正北模式
|
||
getRulerInfo(): Float | 获取地图比例 返回值 地图比例
|
||
setMapStyle(stylemode: Int) | 设置地图模式 MapAutoApi.MAP_STYLE_DAY 日间模式 MapAutoApi.MAP_STYLE_NIGHT 夜间模式 MapAutoApi.MAP_STYLE_VR VR模式
|
||
getMapStyle(): Int | 获取地图模式 返回值 地图模式 1,夜间模式 2, 日间模式 5,VR模式
|
||
setMyLocationStyle(myLocationStyle: MyLocationStyle) | 设置定位类型 LOCATION_TYPE_SHOW: 指定为一次 LOCATION_TYPE_LOCATE:定位一次,且将视角移动到地图中心点 setMyLocationStyle(myLocationStyle: MyLocationStyle) | 设置定位类型 LOCATION_TYPE_SHOW: 指定为一次 LOCATION_TYPE_LOCATE:定位一次,且将视角移动到地图中心点 LOCATION_TYPE_FOLLOW: 连续定位、且将视角移动到地图中心点,定位蓝点跟随设备移动。(1秒1次定位) 默认执行此种模式 LOCATION_TYPE_FOLLOW_NO_CENTER: 连续定位、蓝点不会移动到地图中心点,并且蓝点会跟随设备移动。
|
||
getMyLocationStyle(): MyLocationStyle | 获取定位定位类型
|
||
moveCamera(cameraUpdate: CameraUpdate) | 地图移动 不带动画
|
||
clearPel(): Boolean | 清除所以图元
|
||
setRenderFps(fps: Int) | 设置刷新帧率 fps 刷新帧率
|
||
getRenderFps(): Int | 获取刷新帧率
|
||
setPointToCenter(x: Float, y: Float) | 设置屏幕上的某个像素点为地图中心点。 x: x轴偏移量(0-1),y:y轴偏移量(0-1)
|
||
setAutoSwitchStyle(isAutoSwitch: Boolean) | 设置是否自动切换日语模式 isAutoSwitch:是否自动切换
|
||
setIsUseExtraGPSData(isUseExtraGPSData: Boolean) | 设置是否使用外部数据 isUseExtraGPSData: 是否使用外部数据
|
||
getIsUseExtraGPSData(): Boolean | 获取是否允许传入外部数据 返回值 是否允许传入外部数据
|
||
showBuildings(enabled: Boolean) | 设置是否显示3D建筑物 enabled: 是否显示建筑物 true 显示 false 不显示
|
||
setLockMode(enabled: Boolean) | 设置是否为锁车模式 enable: 是否为锁车模式 true 是 false 否
|
||
getLockMode(): Boolean | 获取是否为锁车模式 返回值 是否为锁车模式 true 是 false 否
|
||
getScalePerPixel(): Float | 获取当前缩放级别下,地图上1像素点对应的长度,单位米
|
||
getCameraPosition(): CameraPosition | 获取当前位置信息
|
||
clearAllMarkers() | 删除所有锚点
|
||
setAnchorRate(rate: Float) | 设置3D锚点比例 rate: 锚点缩放比例
|
||
getEyeHeight() | 获取视点高度
|
||
setEyeHeight(eyeHeight: Float) | 设置视点高度 eyeHeight: 视点高度
|
||
setVerticalViewFieldAngle(r: Float) | 设置视域角 r: 视域角
|
||
getVerticalViewFieldAngle(): Float | 获取视域角
|
||
setSwitchViewAngle(isSwitchViewAngle: Boolean) | 设置双击屏幕视角切换是否打开 isSwitchViewAngle: true:双击屏幕可以切换视角 false 双击屏幕不可以切换视角
|
||
isSwitchViewAngle(): Boolean | 获取视角切换是否打开
|
||
setMapViewVisualAngle(type: Int) | 设置远近视角 type: 视角类型 type MapAutoApi.MAP_STYLE_VR_ANGLE_NEAR 近视角 MapAutoApi.MAP_STYLE_VR_ANGLE_MIDDLE 中视角 MapAutoApi.MAP_STYLE_VR_ANGLE_FAR 远视角
|
||
setScaleVRMode(isScaleVr: Boolean) | 设置能否由VR模式缩放到普通模式 true不能由VR模式缩小到普通模式 false 可以
|
||
setNearViewAnglePosition(lonLatPoint: LonLatPoint, isGps: Boolean) | 切换到近视角 lonLatPoint:切换到近视角显示的位置 isGps true 是GPS坐标 false 不是GPS坐标
|
||
toScreen() | 地图截屏
|
||
setSelfCarPosition(param:Float) | 设置自车相对屏幕的大概位置 param 默认为4.0,范围1.0-6.0
|
||
|
||
|
||
### 4.相关示例
|
||
地图截屏示例如下
|
||
|
||
mapAutoView.getMapAutoViewHelper()?.toScreen()
|
||
mapview.addScreenShotListener(new OnMapScreenShotListener() {
|
||
|
||
@Override
|
||
public void onMapScreenShot(Bitmap bitmap) {
|
||
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||
|
||
if(null == bitmap){
|
||
|
||
return;
|
||
|
||
}
|
||
try {
|
||
|
||
FileOutputStream fos = new FileOutputStream(
|
||
Environment.getExternalStorageDirectory() + "/test_"
|
||
+ sdf.format(new Date()) + ".png");
|
||
boolean b = bitmap.compress(CompressFormat.PNG, 100, fos);
|
||
try {
|
||
fos.flush();
|
||
} catch (IOException e) {
|
||
e.printStackTrace();
|
||
}
|
||
try {
|
||
fos.close();
|
||
} catch (IOException e) {
|
||
e.printStackTrace();
|
||
}
|
||
|
||
handler.post({
|
||
if (b){
|
||
Toast.makeText(context,"截屏成功",Toast.LENGTH_SHORT).show()
|
||
}else{
|
||
Toast.makeText(context,"截屏失败",Toast.LENGTH_SHORT).show()
|
||
|
||
}
|
||
})
|
||
} catch (FileNotFoundException e) {
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
});
|
||
## 三.绘制相关
|
||
|
||
### 1.绘制点标记
|
||
|
||
(1)、默认绘制Marker
|
||
```
|
||
var markerOptions = MarkerOptions()
|
||
.position(lonLatPoint)
|
||
.title("infotitle")
|
||
.snippet("content")
|
||
.isGps(true)
|
||
.markerIcon(BitmapFactory.decodeResource(this.resources, R.mipmap.mk_car))
|
||
.anchor(0.5f, 0.5f)
|
||
.scale(0.5f)
|
||
.controlAngle(true)
|
||
.rotateAngle(30f)
|
||
var marker = MarkerHelper.addMarker(markerOptions)
|
||
```
|
||
(2)、删除全部锚点
|
||
```
|
||
mapAutoView.getMapAutoViewHelper()?.clearAllMarkers()
|
||
```
|
||
(3)、Marker类方法包括以下
|
||
|
||
名称 | 说明
|
||
---- | -----
|
||
setMarkerOptions(markerPtions: MarkerOptions) | 设置markerOption markerPtions:锚点参数
|
||
getMarkeOptions(): MarkerOptions | 获取markerOption
|
||
setClickable(clickable: Boolean) | 锚点是否可点击 clickable: true 可点击, false: 不可点击
|
||
getClickable(): Boolean | 获取锚点是否可点击 返回值 clickable: true 可点击, false: 不可点击
|
||
setScale(scale: Float) | 设置锚点缩放值 scale:缩放值
|
||
setPosition(latLng: LonLatPoint) | 设置锚点位置 latLng 锚点位置
|
||
getPosition(): LonLatPoint | 获取锚点位置 返回值 锚点位置
|
||
remove() | 删除单个锚点
|
||
setTitle(title: String) | 设置infowindow标题 title: infowindow标题
|
||
setTitle(title: String) | 获取infowindow标题 返回值: infowindow标题
|
||
setSnippet(snippet: String) | 设置infowindow内容 snippet:
|
||
getSnippet(): String | 获取infowindow内容 返回值 infowindow内容
|
||
setInfoWindowEnable(isEnable: Boolean) | 设置Marker覆盖物的InfoWindow是否允许显示,默认为false isEnable: true,允许显示 false 不允许显示
|
||
setIcon(bitmap: Bitmap) | 设置锚点图片 bitmap: 锚点图片
|
||
setIcon(view: View) | 设置锚点图片 view: 锚点图片
|
||
marker3DIcon(resId: Int) | 设置3D锚点图片 resId:3D锚点模型资源文件
|
||
setAnchor(anchorU: Float, anchorV: Float) | 设置锚点中心点 anchorU(0-1), anchorV(0-1)
|
||
showInfoWindow() | 显示锚点infoWindow
|
||
hideInfoWindow() | 隐藏锚点infoWindow
|
||
isInfoWindowShown(): Boolean | 返回Marker覆盖物的信息窗口是否显示,true: 显示,false: 不显示。
|
||
setVisible(visible: Boolean) | 设置锚点是否可见 visible true可见 false 不可见
|
||
isVisible(): Boolean | 获取锚点是否可见 返回值 true可见 false 不可见
|
||
setRotateAngle(rotageAngle: Float) | 设置锚点角度 rotageAngle角度
|
||
getRotateAngle(): Float | 获取锚点角度
|
||
setPeriod(period: Int) | 设置多少帧刷新一次图片资源,Marker动画的间隔时间,值越小动画越快。 period:间隔时间
|
||
setInfoWindowOffset(offsetX: Int, offsetY: Int) | 设置infowindow偏移量 offsetX: x轴偏移量 offsetY: Y轴偏移量
|
||
setInfoWindowView(infoView: View) | 设置锚点infoWindow图片 infoView:infowindow对应view
|
||
setToTop() | 设置锚点置顶
|
||
setUnTop() | 取消锚点置顶
|
||
setZIndex(zIndex: Int) | 设置锚点Z值
|
||
setAnchorColor(color: String) | 设置3D锚点颜色 color:3D锚点颜色 "#RRGGBBAA" 示例marker.setAnchorColor("#FF0000FF")
|
||
setDraggable(isDraggable: Boolean) | 设置锚点是否可以拖拽 isDraggable true 可以拖拽 false 不可拖拽
|
||
getDraggable(): Boolean | 获取锚点是否可拖拽 返回值: true 可以拖拽 false 不可拖拽
|
||
setControlAngle(enable: Boolean) | 设置锚点方向是设置方向 enable: true 可以设置方向 false 不可设置方向
|
||
setIcons(icons: ArrayList<*>) | 设置动画锚点图片 icons 动画锚点资源文件
|
||
addDynamicAnchorPostion(lonLatPoint: LonLatPoint, current: Long, duration: Int) | 锚点动态平移 lonLatPoint: 锚点移动到的点 lonLatPoint:当前时间 duration:动画时长
|
||
setTranslateAnimation(animation: MarkerTranslateAnimation) | 设置锚点平移动画 animation: 平移动画
|
||
setMarkerScaleAnimation(animation: MarkerScaleAnimation) | 设置锚点缩放动画 animation:缩放动画
|
||
setRotateAnimation(animation: MarkerRotateAnimation) | 设置锚点旋转动画 animation: 旋转动画
|
||
|
||
|
||
(4)、Marker属性操作集中在 MarkerOptions 类
|
||
|
||
名称 | 说明
|
||
---- | -----
|
||
id | 锚点id
|
||
anchorColor | 3D锚点颜色 "#RRGGBBAA"
|
||
position | 在地图上标记位置的经纬度值。必填参数
|
||
title | 点标记的标题
|
||
snippet | 点标记的内容
|
||
draggable | 点标记是否可拖拽
|
||
visible | 点标记是否可见
|
||
anchor | 锚点中心点
|
||
controlAngle | 锚点角度是否可控制
|
||
rotateAngle | 点标记图标的旋转角度
|
||
zIndex | 点标记的Z坐标
|
||
clickable | 点标记是否可点击
|
||
markerIcon | 点标记的图标
|
||
infoWindowEnable | 锚点是否允许InfoWindow显示
|
||
scale | 设置锚点缩放值
|
||
period | gif锚点刷新图标的时间
|
||
icons | 点标记的图标集合 ArrayList<Int> 3D动画 ArrayList<BitmapDescriptor> 2D动画
|
||
setInfoWindowOffset | 设置infowindow偏移量
|
||
marker3DIcon | 设置3D锚点图标
|
||
isGPS | 锚点坐标是否是gps坐标 默认false
|
||
|
||
(5)、绘制Marker动画效果
|
||
|
||
动画目前包含缩放(MarkerScaleAnimation)平移(MarkerTranslateAnimation)旋转(MarkerRotateAnimation)
|
||
|
||
缩放动画示例代码
|
||
```
|
||
var animation = MarkerScaleAnimation(0f, 1f)
|
||
animation.setDuration(5000)
|
||
animation.setAnimationListener(object : MarkerAnimationListener)
|
||
marker?.setMarkerScaleAnimation(animation)
|
||
marker?.startAnimation()
|
||
```
|
||
平移动画示例代码
|
||
```
|
||
var animation = MarkerTranslateAnimation(lonLatPoints)
|
||
animation.setAnimationListener(object : MarkerAnimationListener)
|
||
animation.setDuration(duration)
|
||
marker?.setTranslateAnimation(animation)
|
||
marker?.startAnimation()
|
||
```
|
||
旋转动画示例代码
|
||
```
|
||
var animation = MarkerRotateAnimation(0f, 360f)
|
||
animation.setAnimationListener(object : MarkerAnimationListener)
|
||
animation.setDuration(1000)
|
||
marker?.setRotateAnimation(animation)
|
||
marker?.startAnimation()
|
||
```
|
||
动态平移示例代码
|
||
```
|
||
val animation = DynamicTranslateAnimation(lonLatPoint)
|
||
animation.setCurrent(System.currentTimeMillis())
|
||
animation.setDuration(5000)
|
||
animation.setAnimationListener(object: MarkerAnimationListener)
|
||
marker?.addDynamicAnchorPostion(animation)
|
||
```
|
||
动画监听事件
|
||
```
|
||
interface MarkerAnimationListener {
|
||
fun onAnimationStart(animation: Animation)//开始动画
|
||
|
||
fun onAnimationEnd(animation: Animation)//结束动画
|
||
|
||
fun onAnimationRepeat(animation: Animation)//暂未实现
|
||
}
|
||
设置监听
|
||
animation.setAnimationListener(object : MarkerAnimationListener)
|
||
```
|
||
添加动态锚点示例代码如下
|
||
|
||
```
|
||
fun addDymicMarker(lonLatPoint1: LonLatPoint, duration: Long) {
|
||
val lonLatPoint = LonLatPoint(lonLatPoint1.longitude + 0.00005, lonLatPoint1.latitude + 0.00009,lonLatPoint1.angle)
|
||
if(dymicMarker == null){
|
||
var markerOptions = MarkerOptions()
|
||
.position(lonLatPoint)
|
||
.title("title center").zIndex(100)
|
||
.snippet("content center")
|
||
.setGps(true)
|
||
.marker3DIcon(R.raw.daba)//.anchorColor("#FF0000FF")
|
||
.controlAngle(true)
|
||
.rotateAngle(lonLatPoint1.angle)
|
||
dymicMarker = MarkerHelper.addMarker(markerOptions)
|
||
dymicMarker?.setOnMarkClickListener(this)
|
||
}else{
|
||
dymicMarker?.addDynamicAnchorPostion(lonLatPoint,System.currentTimeMillis(),duration.toInt())
|
||
}
|
||
}
|
||
```
|
||
(6)、绘制动画锚点
|
||
|
||
2D动画锚点 示例代码
|
||
```
|
||
val marker = MarkerHelper.addMarker(MarkerOptions().position(lonLatPoint).period(500))
|
||
var list: ArrayList<BitmapDescriptor> = ArrayList<BitmapDescriptor>()
|
||
list.add(BitmapDescriptor(BitmapFactory.decodeResource(resources, R.drawable.icon_tts_000)))
|
||
list.add(BitmapDescriptor(BitmapFactory.decodeResource(resources, R.drawable.icon_tts_001)))
|
||
list.add(BitmapDescriptor(BitmapFactory.decodeResource(resources, R.drawable.icon_tts_002)))
|
||
marker?.setIcons(list)
|
||
```
|
||
绘制3D动画锚点 最多支持10个模型 示例代码
|
||
```
|
||
marker = MarkerHelper.addMarker(MarkerOptions().marker3DIcon(R.raw.gq_1).position(lonLatPoint).period(100))
|
||
iconList.add(R.raw.gq_1)
|
||
iconList.add(R.raw.gq_2)
|
||
iconList.add(R.raw.gq_3)
|
||
iconList.add(R.raw.gq_4)
|
||
···
|
||
marker?.setIcons(iconList)
|
||
```
|
||
(7)、绘制海量点
|
||
```
|
||
mapAutoView.getMapAutoViewHelper()?.addMarkers(multiPointOverlayOptions)
|
||
```
|
||
示例代码如下
|
||
```
|
||
|
||
var multiPointOverlayOptions = MultiPointOverlayOptions()
|
||
multiPointOverlayOptions.setMarkerIcon(R.mipmap.icon_map_marker_car_gray)
|
||
for (lonlat in lonlatpoints) {
|
||
markerOptions = MarkerOptions().position(lonlat).setMarkerIconName(multiPointOverlayOptions.markerIconName)
|
||
list.add(markerOptions)
|
||
}
|
||
multiPointOverlayOptions.setMarkerData(list)
|
||
markersController = mapAutoView.getMapAutoViewHelper()?.addMarkers(multiPointOverlayOptions)
|
||
|
||
```
|
||
(8)、锚点事件
|
||
|
||
Marker点击事件
|
||
```
|
||
marker?.setOnMarkClickListener(object : OnMarkClickListener{
|
||
override fun onMarkClick(marker: Marker) {
|
||
|
||
}
|
||
})
|
||
```
|
||
Marker拖拽事件
|
||
```
|
||
marker?.setOnMarkerDragListener(object : OnMarkerDragListener{
|
||
override fun onMarkerDragStart(var1: Marker?) {
|
||
TODO("Not yet implemented")
|
||
}
|
||
|
||
override fun onMarkerDrag(var1: Marker?) {
|
||
TODO("Not yet implemented")
|
||
}
|
||
|
||
override fun onMarkerDragEnd(var1: Marker?) {
|
||
TODO("Not yet implemented")
|
||
}
|
||
})
|
||
```
|
||
(9)、绘制infoWindow
|
||
|
||
默认的 Infowindow 只显示 Marker 对象的两个属性,一个是 title 和另一个 snippet。
|
||
SDK 为用户提供了默认的 InfoWindow 样式,调用 Marker 类的 showInfoWindow() 和 hideInfoWindow() 方法可以
|
||
控制显示和隐藏。调用setTitle() 与 setSnippet()可以改变Marker的title以及snippet。
|
||
|
||
绘制自定义 InfoWindow
|
||
|
||
InfoWindowAdapter是一个接口,其中有两个方法需要实现,依次来看一下:
|
||
|
||
```
|
||
interface InfoWindowAdapter{
|
||
fun getInfoWindow(marker: Marker?): View?
|
||
fun getInfoContents(marker: Marker?):View?
|
||
}
|
||
```
|
||
当实现getInfoWindow()方法并返回有效值时(返回值不为空,则视为有效),SDK 将不会使用默认的样式,而采用此方法返回的样式(即 View)。
|
||
|
||
```
|
||
MapAutoApi.setInfoWindowAdapter(object : InfoWindowAdapter {
|
||
override fun getInfoContents(marker: Marker?): View? {
|
||
return null
|
||
}
|
||
|
||
override fun getInfoWindow(marker: Marker?): View? {
|
||
view = LayoutInflater.from(this).inflate(R.layout.layout_info_window, null, false)
|
||
tv_title = view?.findViewById(R.id.info_title) as TextView
|
||
tv_snippet = view?.findViewById(R.id.info_content) as TextView
|
||
tv_title?.text = marker?.getTitle()
|
||
tv_snippet?.text = marker?.getSnippet()
|
||
return view
|
||
}
|
||
})
|
||
```
|
||
(10)、批量更新锚点位置
|
||
updateBatchMarkerPositon(list:ArrayList<MarkerOptions>?,current:Long)
|
||
示例
|
||
```
|
||
private fun addMarkerOptions(otherCar: OtherCar,duration:Long) {
|
||
var markerOptions : MarkerOptions? = markerOptionsMap.get(otherCar.id)
|
||
val lonLatPoint = LonLatPoint(otherCar.lon, otherCar.lat,otherCar.angle.toFloat())
|
||
val mode = getModelRes(otherCar.type)
|
||
if(markerOptions == null){
|
||
markerOptions = MarkerOptions("${otherCar.id}")
|
||
.setGps(true)
|
||
.position(lonLatPoint)
|
||
.title("title center").zIndex(100)
|
||
.snippet("content center")
|
||
.marker3DIcon(mode)//.anchorColor("#FF0000FF")
|
||
.controlAngle(true)
|
||
.rotateAngle(otherCar.angle.toFloat())
|
||
.duration(duration.toInt())
|
||
markerOptionsMap.put(otherCar.id,markerOptions)
|
||
}else{
|
||
markerOptions = markerOptions.position(lonLatPoint)
|
||
.marker3DIcon(mode)
|
||
.controlAngle(true)
|
||
.rotateAngle(otherCar.angle.toFloat())
|
||
.duration(duration.toInt())
|
||
}
|
||
optionsList.add(markerOptions)
|
||
}
|
||
|
||
val currentMarkerList = ArrayList<Int>()
|
||
for(car in others) {
|
||
addMarkerOptions(car,duration)
|
||
currentMarkerList.add(car.id)
|
||
}
|
||
MarkerHelper.updateBatchMarkerPositon(optionsList,System.currentTimeMillis())
|
||
optionsList.clear()
|
||
|
||
for(key in markerOptionsMap.keys){
|
||
if(!currentMarkerList.contains(key)){
|
||
delelteMarkerList.add(key)
|
||
}
|
||
}
|
||
|
||
for(value in delelteMarkerList){
|
||
val marker = markerOptionsMap.remove(value)
|
||
marker?.let{
|
||
MarkerHelper.removeMarker(it.getId())
|
||
}
|
||
}
|
||
delelteMarkerList.clear()
|
||
```
|
||
|
||
|
||
### 2.绘制线
|
||
(1)、绘制线是由 Polyline 类定义实现的,线由一组经纬度点连接而成,绘制一条线与点标记一样,Polyline 的属性操作集中在 PolylineOptions 类中,添加一条线的示例如下:
|
||
```
|
||
val lons = java.util.ArrayList<LonLatPoint>()
|
||
lons.add(LonLatPoint(116.414571,39.969015))
|
||
lons.add(LonLatPoint(116.416695,39.96908))
|
||
lons.add(LonLatPoint(116.417988,39.969093))
|
||
lons.add(LonLatPoint(116.417961,39.96973))
|
||
poline = mapAutoView.getMapAutoViewHelper()?.drawThickLine(PolylineOptions().Color(Color.argb(255, 255, 0, 0)).lonLatPoints(lons).setLineWidth(5f))
|
||
|
||
```
|
||
(2)、绘制渐变示例 渐变线颜色不能比点数量多
|
||
```
|
||
val lons = java.util.ArrayList<LonLatPoint>()
|
||
lons.add(LonLatPoint(116.414971, 39.965015))
|
||
lons.add(LonLatPoint(116.414971, 39.96608))
|
||
lons.add(LonLatPoint(116.414971, 39.967093))
|
||
lons.add(LonLatPoint(116.414971, 39.96873))
|
||
var valuesArr = arrayListOf<Int>()
|
||
valuesArr.add(Color.argb(255, 255, 0, 0))
|
||
valuesArr.add(Color.argb(255, 0, 255, 0))
|
||
valuesArr.add(Color.argb(255, 255, 0, 0))
|
||
valuesArr.add(Color.argb(255, 0, 0, 255))
|
||
mapAutoView.getMapAutoViewHelper()?.drawThickLine(PolylineOptions().lonLatPoints(lons).lineWidth(10f).colorValues(valuesArr).useGradient(true))
|
||
```
|
||
(3)、绘制多彩线示例 多彩线颜色要比点少
|
||
```
|
||
val lons = java.util.ArrayList<LonLatPoint>()
|
||
lons.add(LonLatPoint(116.414571, 39.965015))
|
||
lons.add(LonLatPoint(116.414571, 39.96608))
|
||
lons.add(LonLatPoint(116.414571, 39.967093))
|
||
lons.add(LonLatPoint(116.414571, 39.96873))
|
||
var valuesArr = arrayListOf<Int>()
|
||
valuesArr.add(Color.argb(100, 255, 0, 0))
|
||
valuesArr.add(Color.argb(100, 0, 255, 0))
|
||
valuesArr.add(Color.argb(100, 0, 0, 255))
|
||
mapAutoView.getMapAutoViewHelper()?.drawThickLine(PolylineOptions().useColorful(true).lonLatPoints(lons).lineWidth(5f).colorValues(valuesArr))
|
||
|
||
```
|
||
(4)、绘制线常用方法,这些方法在PolylineOptions类实现
|
||
|
||
名称 | 说明
|
||
---- | -----
|
||
lonLatPoints | 设置线的位置
|
||
lineWidth(float lineWidth) | 设置线宽 lineWidth: 线宽
|
||
color(int color) | 线的颜色 color 颜色
|
||
colorValues(List<Integer> mColorValues) | 多彩线或渐变线的颜色 多彩线颜色要比点少 渐变线颜色不能比点数量多
|
||
dottedLine(boolean dottedLine) | 设置是否画虚线,默认为false,画实线。 dottedLine true 虚线 false 实线
|
||
dottedLineType(int type) | 设置虚线的类型 DOT_LINE_TYPE_SHORT_LINE //空隙长 DOT_LINE_TYPE_LONG_LINE 实线长
|
||
useGradient(boolean isGradient) | 设置是否使用渐变色 isGradient true 渐变线 false 不是渐变线 默认 false
|
||
useColorful | 设置是否是多彩线
|
||
setGps | 是否是GPS坐标
|
||
|
||
(5)、Polyline类
|
||
|
||
名称 | 说明
|
||
---- | -----
|
||
setWidth(float lineWidth) | 设置线宽 lineWidth: 线宽
|
||
setColor(int color) | 线的颜色 color: 颜色
|
||
setZIndex(float zIndex) | 设置线段Z轴的值 zIndex: Z值
|
||
setVisible(boolean visible) | 设置线段的可见性 visible: 是否可见 true: 可见 false: 不可见
|
||
setPoints(List<LonLatPoint> lonLatPoints) | 设置线段位置 lonLatPoints: 线的位置
|
||
remove() | 删除单个线
|
||
setDottedLine(boolean dottedLine) | 设置是否虚线 dottedLine true 是虚线 false 实线
|
||
isDottedLine() | 获取是否虚线 返回值 true 是虚线 false 实线
|
||
setOption(PolylineOptions option) | 设置属性
|
||
|
||
|
||
|
||
### 3.绘制面
|
||
(1)、绘制圆形
|
||
```
|
||
val lons = java.util.ArrayList<LonLatPoint>()
|
||
lons.add(LonLatPoint(116.407317, 39.970309))
|
||
lons.add(LonLatPoint(116.413539, 39.968924))
|
||
var circleOptions = CircleOptions().setRadius(100).setColor(Color.argb(100, 0, 255, 0)).setLineWidth(10).setLonLatPoints(lons)
|
||
circleController = mapAutoView.getMapAutoViewHelper()?.drawCircle(circleOptions)
|
||
```
|
||
(2)、绘制矩形
|
||
```
|
||
val lons = java.util.ArrayList<LonLatPoint>()
|
||
lons.add(LonLatPoint(116.401539, 39.968924))
|
||
lons.add(LonLatPoint(116.407539, 39.968924))
|
||
lons.add(LonLatPoint(116.401539, 39.967000))
|
||
lons.add(LonLatPoint(116.407539, 39.967000))
|
||
var polylineOptions = PolylineOptions().setColor(Color.argb(100, 0, 100, 255)).setLineWidth(10f).setLonLatPoints(lons)
|
||
rectController = mapAutoView.getMapAutoViewHelper()?.drawRect(polylineOptions)
|
||
```
|
||
(3)、绘制椭圆
|
||
```
|
||
val lons = java.util.ArrayList<LonLatPoint>()
|
||
lons.add(LonLatPoint(116.407539, 39.968924))
|
||
lons.add(LonLatPoint(116.407539, 39.975024))
|
||
lons.add(LonLatPoint(116.401639, 39.969000))
|
||
lons.add(LonLatPoint(116.405665, 39.967924))
|
||
var polylineOptions = PolylineOptions().setColor(Color.argb(100, 0, 255, 255)).setLineWidth(10f).setLonLatPoints(lons)
|
||
ellipseController = mapAutoView.getMapAutoViewHelper()?.drawEllipse(polylineOptions)
|
||
```
|
||
(4)、绘制多边形
|
||
```
|
||
val lons = java.util.ArrayList<LonLatPoint>()
|
||
lons.add(LonLatPoint(116.39764, 39.968437))
|
||
lons.add(LonLatPoint(116.407768, 39.969062))
|
||
lons.add(LonLatPoint(116.408369, 39.959359))
|
||
lons.add(LonLatPoint(116.398113, 39.959096))
|
||
var polylineOptions = PolylineOptions().setColor(Color.argb(255, 255, 0, 255)).setLineWidth(10f).setLonLatPoints(lons)
|
||
polygonController = mapAutoView.getMapAutoViewHelper()?.drawPolygon(polylineOptions)
|
||
```
|
||
|
||
|
||
## 四.地图数据相关
|
||
|
||
### 1.获取POI数据
|
||
|
||
>POI(Point of Interest,兴趣点)。在地图表达中,一个 POI 可代表一栋大厦、一家商铺、一处景点等等。通过POI搜索,完成找餐馆、找景点、找厕所等等的功能。地图 SDK 的搜索功能提供多种获取 POI 数据的接口,下文将逐一介绍。
|
||
|
||
#### 1.1关键字检索POI
|
||
|
||
根据关键字检索适用于在某个城市搜索某个名称相关的POI,例如:查找北京市的“肯德基”。
|
||
|
||
注意:
|
||
|
||
(1)、关键字未设置城市信息(默认为全国搜索)时,如果涉及多个城市数据返回,仅会返回建议城市,请根据APP需求,选取城市进行搜索。
|
||
|
||
(2)、不设置POI的类别,默认返回“餐饮服务”、“商务住宅”、“生活服务”这三种类别的POI,下方提供了POI分类码表,请按照列表内容设置希望检索的POI类型。(建议使用POI类型的代码进行检索)
|
||
|
||
#### 1.2实现关键字检索的步骤如下:
|
||
(1)、继承 OnPoiSearchListener 监听。
|
||
|
||
(2)、构造 Query 对象,通过 Query(keyword: String, city: String, category: String) 设置搜索条件。
|
||
|
||
```
|
||
query = new Query(keyWord, "", "");
|
||
//keyWord表示搜索字符串,
|
||
//第二个参数表示POI搜索区域,
|
||
//category,搜索类型
|
||
query.setPageSize(10);// 设置每页最多返回多少条poiitem
|
||
query.setPageNum(currentPage);//设置查询页码
|
||
```
|
||
|
||
|
||
#### 1.3、构造 PoiSearch 对象,并设置监听。
|
||
```
|
||
poiSearch = new PoiSearch(this, query);
|
||
poiSearch.setOnPoiSearchListener(this);
|
||
```
|
||
#### 1.4、调用 PoiSearch 的 searchPOIAsyn() 方法发送请求。
|
||
```
|
||
poiSearch.searchPOIAsyn();
|
||
```
|
||
#### 1.5、通过回调接口 onPoiSearched 解析返回的结果,将查询到的 POI 以绘制点的方式显示在地图上。
|
||
#### 1.6、说明:
|
||
1)可以在回调中解析poiSearchResults,获取POI信息。
|
||
|
||
2)poiSearchResults.getItems()可以获取到PoiItem列表,Poi详细信息可参考PoiItem类。
|
||
|
||
<!--3)若当前城市查询不到所需POI信息,可以通过result.getSearchSuggestionCitys()获取当前Poi搜索的建议城市。-->
|
||
|
||
<!--4)如果搜索关键字明显为误输入,则可通过result.getSearchSuggestionKeywords()方法得到搜索关键词建议。-->
|
||
|
||
5)返回结果成功或者失败的响应码。0为成功,其他为失败
|
||
|
||
```
|
||
public void onPoiSearched(poiSearchResults: PoiSearchResults?, code: Int)
|
||
//解析poiSearchResults获取POI信息
|
||
}
|
||
```
|
||
|
||
### 2. ID检索POI
|
||
|
||
通过关键字检索、周边检索以及多边形检索,可通过ID检索来获取POI完整详细信息。
|
||
|
||
实现步骤如下:
|
||
|
||
(1)、继承 OnPoiSearchListener 监听。
|
||
|
||
(2)、构造 PoiSearch 对象,并设置监听。对于ID检索,query参数设置成 null。
|
||
|
||
```
|
||
poiSearch = new PoiSearch(this, null);
|
||
poiSearch.setOnPoiSearchListener(this);
|
||
```
|
||
(3)、调用 PoiSearch 的 searchPOIIdAsyn(java.lang.String poiID) 方法发送请求。
|
||
```
|
||
poiSearch.searchPOIIdAsyn(ID);// 异步搜索
|
||
```
|
||
(4)、通过回调接口 onPoiItemSearched 解析返回的结果。由于是检索具体的某一个POI,直接回调该POI对象 PoiItem。
|
||
```
|
||
@Override
|
||
public void onPoiItemSearched(PoiItem item, int rCode) {
|
||
//获取PoiItem获取POI的详细信息
|
||
}
|
||
```
|
||
|
||
### 3.输入内容自动提示
|
||
|
||
输入提示是指根据用户输入的关键词,给出相应的提示信息,将最有可能的搜索词呈现给用户,以减少用户输入信息,提升用户体验。如:输入“方恒”,提示“方恒国际中心A座”,“方恒购物中心”等。
|
||
|
||
实现输入提示的步骤如下:
|
||
|
||
(1)、继承 InputtipsListener 监听。
|
||
(2)、构造 InputtipsQuery 对象,通过 InputtipsQuery(java.lang.String keyword, java.lang.String city) 设置搜索条件。
|
||
```
|
||
//第二个参数传入null或者“”代表在全国进行检索,否则按照传入的city进行检索
|
||
InputtipsQuery inputquery = new InputtipsQuery(newText, city);
|
||
```
|
||
(3)、构造 Inputtips 对象,并设置监听。
|
||
```
|
||
Inputtips inputTips = new Inputtips(this, inputquery);
|
||
inputTips.setInputtipsListener(this);
|
||
```
|
||
(4)、调用 PoiSearch 的 requestInputtipsAsyn() 方法发送请求。
|
||
```
|
||
inputTips.requestInputtipsAsyn();
|
||
```
|
||
(5)、通过回调接口 onGetInputtips 解析返回的结果,获取输入提示返回的信息。
|
||
|
||
(6)、说明:
|
||
|
||
a.在回调中解析 tipList,获取输入提示词的相关信息。
|
||
|
||
b.tipList 数组中的对象是 Tip ,Tip 类中包含 PoiID、Adcode、District、Name 等信息。
|
||
|
||
|
||
### 4.POI 分类
|
||
id | 说明
|
||
---- | -----
|
||
4 | 引导参照点
|
||
5 | 汽车维修
|
||
6 | 加油站
|
||
7 | 租车
|
||
8 | 洗车
|
||
9 | 汽车销售
|
||
10 | 摩托车销售
|
||
12 | 室内停车场
|
||
13 | 露天停车场
|
||
14 | 休息区
|
||
16 | 野营
|
||
21 | 宾馆/汽车旅馆
|
||
22 | 饭店
|
||
24 | 咖啡店
|
||
25 | 酒吧
|
||
26 | 电影院
|
||
27 | 博物馆
|
||
28 | 剧场
|
||
29 | 图书馆
|
||
30 | 医院
|
||
32 | 牙科诊所
|
||
33 | 药房
|
||
34 | 宠物诊所
|
||
35 | 警察局
|
||
36 | 邮局
|
||
37 | 市政府
|
||
38 | 大使馆
|
||
39 | 法院
|
||
40 | 政府机构
|
||
41 | 社区活动中心
|
||
42 | 购物中心
|
||
43 | 商店
|
||
44 | 银行
|
||
45 | ATM
|
||
46 | 货币兑换
|
||
47 | 旅游服务处
|
||
48 | 旅行社
|
||
49 | 旅游景点
|
||
50 | 历史遗迹
|
||
54 | 动物园
|
||
55 | 游乐园
|
||
57 | 露天体育场
|
||
58 | 体育中心
|
||
59 | 娱乐活动
|
||
60 | 溜冰场
|
||
61 | 游泳池
|
||
62 | 高尔夫球场
|
||
63 | 码头
|
||
66 | 商业设施
|
||
67 | 展览馆
|
||
68 | 火车站
|
||
69 | 公交车站
|
||
71 | 飞机场
|
||
75 | 紧急医疗服务
|
||
77 | 消防队
|
||
78 | 礼拜场所
|
||
79 | 教育
|
||
83 | 公共休息区/公厕
|
||
|
||
### 5.地图相关数据
|
||
地图数据获取在MapDataApi类中
|
||
|
||
id | 说明
|
||
---- | -----
|
||
getRouteInfo(centerLon: Float,centerLat: Float, coor: Int, type: Int) | 获取道路信息 * coor 坐标系,0 GPS ,1 gcj
|
||
getMatchRoadInfo(lonLatPoints: List<LonLatPoint>,bGetAllPoints: Boolean): List<LonLatPoint>? | 获取道路关键点数据
|
||
getRouteAngle(startLonLat: LonLatPoint, endLonLat: LonLatPoint): Float | 获取行车方向
|
||
getSinglePointMatchRoad(lon: Double, lat: Double, angle: Float, isGps: Boolean, isRTK: Boolean): SinglePointRoadInfo | 获取匹配道路数据 isGps 是否是GPS数据 isRTK 是否是高精数据
|
||
getLaneInfo(tileId: Long, routeId: Int): ArrayList<Lane> | 获取车道中心线数据
|
||
GetDisFromPointToLine( ptOrg:LonLatPoint, pLine:ArrayList<LonLatPoint>, ptMatch:LonLatPoint, nSegmentOrder:Int):Double | 获取点到线的距离
|
||
getOffRoadDistance(lon: Double, lat: Double, angle: Float): Double | 获取点与道路边界的距离
|
||
|
||
|
||
|
||
## 五.地图计算工具
|
||
### 1.坐标转换
|
||
(1)、屏幕坐标转换为地图坐标
|
||
```
|
||
MapTools.fromScreenLocation(android.graphics.Point paramPoint)//paramPoint 屏幕坐标点
|
||
```
|
||
(2)、地图坐标转换为屏幕坐标
|
||
```
|
||
MapTools.toScreenLocation(latLonPoint: LatLonPoint)//latLonPoint: 地图坐标点
|
||
```
|
||
(3)、批量经纬度转屏幕坐标
|
||
```
|
||
MapTools.toScreenLocations(data: List<LonLatPoint>): List<Point>//data: 批量地图坐标点 返回值: 批量屏幕坐标点
|
||
```
|
||
(4)、批量屏幕坐标转纬度
|
||
```
|
||
MapTools.fromScreenLocations(data: List<Point>): List<LonLatPoint>//data: 批量屏幕坐标点 返回值: 批量地图坐标点
|
||
```
|
||
### 2.获取屏幕可见区域
|
||
|
||
(1)、返回一个在屏幕坐标与地理经纬度坐标之间的可见区域
|
||
```
|
||
MapTools.getVisibleRegion(): VisibleRegion//返回值 屏幕可见区域
|
||
```
|
||
(2)、获取两点间距离
|
||
```
|
||
MapTools.distance(x1: Double, y1: Double, x2: Double, y2: Double): Double//x1:第一个点的x轴坐标 y1:第一个点的y轴坐标 x2:第二个点的x轴坐标 y2:第二个点的y轴坐标
|
||
```
|