运单起始点路径规划

This commit is contained in:
lijia 2024-04-01 16:32:03 +08:00
parent e432812ce4
commit 70b6d2a40d
12 changed files with 721 additions and 20 deletions

View File

@ -0,0 +1,31 @@
package com.dahe.gldriver.callback
import android.view.View
import com.amap.api.navi.INaviInfoCallback
import com.amap.api.navi.model.AMapNaviLocation
import com.amap.api.services.route.BusRouteResult
import com.amap.api.services.route.DriveRouteResult
import com.amap.api.services.route.RideRouteResult
import com.amap.api.services.route.RouteSearch
import com.amap.api.services.route.RouteSearchV2.OnRouteSearchListener
import com.amap.api.services.route.WalkRouteResult
/**
* @ClassName MyOnInitNaviFailure
* @Author john
* @Date 2024/3/21 16:12
* @Description TODO
*/
open class MyOnRouteSerach : RouteSearch.OnRouteSearchListener {
override fun onBusRouteSearched(p0: BusRouteResult?, p1: Int) {
}
override fun onDriveRouteSearched(p0: DriveRouteResult?, p1: Int) {
}
override fun onWalkRouteSearched(p0: WalkRouteResult?, p1: Int) {
}
override fun onRideRouteSearched(p0: RideRouteResult?, p1: Int) {
}
}

View File

@ -25,6 +25,7 @@ import com.dahe.gldriver.net.DataManager
import com.dahe.gldriver.net.RxHttpCallBack
import com.dahe.gldriver.utils.GDLocationUtils
import com.dahe.gldriver.utils.LocationUtils
import com.dahe.gldriver.utils.NaviUtils
import com.dahe.gldriver.utils.OrderUtils
import com.dahe.mylibrary.base.BaseActivity
import com.dahe.mylibrary.net.CommonResponseBean
@ -73,14 +74,12 @@ class WaybillLoadActivity : BaseActivity<ActivityWaybillLoadBinding>() {
uiSettings.run { isZoomControlsEnabled = false }
}
llGoStart.setOnClickListener {
if (!::loadPos.isInitialized)
if (!::loadPos.isInitialized){
showToast("请等待定位成功")
return@setOnClickListener
AmapNaviPage.getInstance().showRouteActivity(
applicationContext,
AmapNaviParams(null, null, Poi("天安门", loadPos, ""), AmapNaviType.DRIVER),
object : MyINaviInfoCallback() {}
)
}
NaviUtils.getInstance().goNextPoint(mContext,loadPos,loadAddress)
}
btnRight.setOnClickListener {
@ -109,6 +108,7 @@ class WaybillLoadActivity : BaseActivity<ActivityWaybillLoadBinding>() {
val load = orderBean.orderChildList.first { it.type == "1" }
var distance = ""
loadPos = LatLng(load.latitude.toDouble(), load.longitude.toDouble())
loadAddress = load.address
LocationUtils.getInstance().changeCamera(loadPos, aMap!!)
if (::gdLatLng.isInitialized) {
distance = LocationUtils.getInstance().getDistance(
@ -225,6 +225,7 @@ class WaybillLoadActivity : BaseActivity<ActivityWaybillLoadBinding>() {
lateinit var gdLatLng: LatLng
lateinit var loadPos: LatLng
lateinit var loadAddress: String
fun getLocation() {
GDLocationUtils.instance.getLocation(mContext) {
//errCode等于0代表定位成功其他的为定位失败具体的可以参照官网定位错误码说明

View File

@ -1,27 +1,18 @@
package com.dahe.gldriver.ui.waybill.activity
import android.Manifest
import android.content.res.Resources
import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.widget.LinearLayout
import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.amap.api.maps.AMap
import com.amap.api.maps.model.LatLng
import com.amap.api.maps.model.Poi
import com.amap.api.navi.AmapNaviPage
import com.amap.api.navi.AmapNaviParams
import com.amap.api.navi.AmapNaviType
import com.amap.api.navi.INaviInfoCallback
import com.amap.api.navi.model.AMapNaviLocation
import com.dahe.gldriver.R
import com.dahe.gldriver.adapter.WaybillNodeAdapter
import com.dahe.gldriver.base.AppConfig
import com.dahe.gldriver.bean.OrderDetailBean
import com.dahe.gldriver.callback.MyINaviInfoCallback
import com.dahe.gldriver.databinding.ActivityWaybillUnloadBinding
import com.dahe.gldriver.net.BaseObserver
import com.dahe.gldriver.net.DataManager
@ -79,7 +70,16 @@ class WaybillUnlLoadActivity : BaseActivity<ActivityWaybillUnloadBinding>() {
return@setOnClickListener
}
NaviUtils.getInstance().goNextPoint(mContext,loadPos)
NaviUtils.getInstance().goNextPoint(mContext,loadPos,loadAddress)
}
llRoutes.setOnClickListener {
if (!::unLoadPos.isInitialized||!::loadPos.isInitialized) {
showToast("缺少起始点定位信息,请返回重试")
return@setOnClickListener
}
NaviUtils.getInstance().getRoute(mContext,loadPos,unLoadPos,loadAddress,unLoadAddress)
}
@ -105,9 +105,14 @@ class WaybillUnlLoadActivity : BaseActivity<ActivityWaybillUnloadBinding>() {
super.onSuccess(t)
orderBean = t.data
val load = orderBean.orderChildList.first { it.type == "1" }
val unLoad = orderBean.orderChildList.last { it.type == "2" }
var distance = ""
loadPos = LatLng(load.latitude.toDouble(), load.longitude.toDouble())
LocationUtils.getInstance().changeCamera(loadPos, aMap!!)
unLoadPos = LatLng(unLoad.latitude.toDouble(), unLoad.longitude.toDouble())
loadAddress = load.address
unLoadAddress = unLoad.address
LocationUtils.getInstance().searchRouteResult(mContext,loadPos,unLoadPos,aMap)
if (::gdLatLng.isInitialized) {
distance = LocationUtils.getInstance().getDistance(
gdLatLng,
@ -219,6 +224,9 @@ class WaybillUnlLoadActivity : BaseActivity<ActivityWaybillUnloadBinding>() {
lateinit var gdLatLng: LatLng
lateinit var loadPos: LatLng
lateinit var unLoadPos: LatLng
lateinit var loadAddress: String
lateinit var unLoadAddress: String
fun getLocation() {
GDLocationUtils.instance.getLocation(mContext) {
//errCode等于0代表定位成功其他的为定位失败具体的可以参照官网定位错误码说明

View File

@ -1,5 +1,6 @@
package com.dahe.gldriver.utils
import android.content.Context
import com.amap.api.maps.AMap
import com.amap.api.maps.AMapException
import com.amap.api.maps.CameraUpdateFactory
@ -7,7 +8,19 @@ import com.amap.api.maps.model.BitmapDescriptorFactory
import com.amap.api.maps.model.CameraPosition
import com.amap.api.maps.model.LatLng
import com.amap.api.maps.model.MarkerOptions
import com.amap.api.maps.model.Poi
import com.amap.api.navi.AmapNaviPage
import com.amap.api.navi.AmapNaviParams
import com.amap.api.navi.AmapNaviType
import com.amap.api.services.core.AMapException.CODE_AMAP_SUCCESS
import com.amap.api.services.core.LatLonPoint
import com.amap.api.services.route.DrivePath
import com.amap.api.services.route.DriveRouteResult
import com.amap.api.services.route.RouteSearch
import com.dahe.gldriver.R
import com.dahe.gldriver.callback.MyINaviInfoCallback
import com.dahe.gldriver.callback.MyOnRouteSerach
import com.dahe.gldriver.weight.overlay.DrivingRouteOverlay
import com.dahe.mylibrary.base.SingletonNoPHolder
/**
@ -71,8 +84,23 @@ class LocationUtils private constructor() {
}
}
fun changeCamera(latLng: LatLng,aMap: AMap){
aMap.moveCamera(CameraUpdateFactory.newCameraPosition(CameraPosition(latLng,12f,30f,30f)))
/**
* 改变地图中心点
* @param latLng LatLng
* @param aMap AMap
*/
fun changeCamera(latLng: LatLng, aMap: AMap) {
aMap.moveCamera(
CameraUpdateFactory.newCameraPosition(
CameraPosition(
latLng,
12f,
30f,
30f
)
)
)
aMap.clear()
aMap.addMarker(
MarkerOptions().position(latLng)
@ -81,4 +109,75 @@ class LocationUtils private constructor() {
)
)
}
/**
* 开始搜索路径规划方案
* @param context Context
* @param load LatLng
* @param unload LatLng
* @param aMap AMap
*/
fun searchRouteResult(context: Context, load: LatLng, unload: LatLng, aMap: AMap) {
try {
var mRouteSearch = RouteSearch(context)
mRouteSearch.setRouteSearchListener(object : MyOnRouteSerach() {
override fun onDriveRouteSearched(p0: DriveRouteResult?, p1: Int) {
super.onDriveRouteSearched(p0, p1)
if (p1 == CODE_AMAP_SUCCESS) {
if (p0 != null && p0.getPaths() != null && p0.paths.size > 0) {
val drivePath: DrivePath = p0.paths[0] ?: return
val drivingRouteOverlay = DrivingRouteOverlay(
context, aMap, drivePath,
p0.startPos,
p0.targetPos, null
).apply {
setNodeIconVisibility(false) //设置节点marker是否显示
setIsColorfulline(true) //是否用颜色展示交通拥堵情况默认true
removeFromMap()
addToMap()
zoomToSpan()
}
}
}
}
})
val fromAndTo = RouteSearch.FromAndTo(
LatLonPoint(load.latitude, load.longitude),
LatLonPoint(unload.latitude, unload.longitude)
)
val query = RouteSearch.DriveRouteQuery(
fromAndTo, RouteSearch.DrivingDefault, null,
null, ""
) // 第一个参数表示路径规划的起点和终点,第二个参数表示驾车模式,第三个参数表示途经点,第四个参数表示避让区域,第五个参数表示避让道路
mRouteSearch.calculateDriveRouteAsyn(query) // 异步路径规划驾车模式查询
} catch (e: Exception) {
}
}
/**
* 规划路径
* @param context Context
* @param load LatLng
* @param unload LatLng
* @param startAddress String
* @param endAddress String
*/
fun getRoutes(context: Context, load: LatLng, unload: LatLng, startAddress: String = "", endAddress: String = "") {
val params = AmapNaviParams(
Poi(startAddress, load, ""),
null,
Poi(endAddress, unload, ""),
AmapNaviType.DRIVER
)
params.setUseInnerVoice(true)
AmapNaviPage.getInstance()
.showRouteActivity(context, params, object : MyINaviInfoCallback() {})
}
}

View File

@ -7,6 +7,7 @@ import com.amap.api.navi.AmapNaviPage
import com.amap.api.navi.AmapNaviParams
import com.amap.api.navi.AmapNaviType
import com.dahe.gldriver.callback.MyINaviInfoCallback
import com.dahe.gldriver.weight.overlay.CustomAmapRouteActivity
import com.dahe.mylibrary.base.SingletonNoPHolder
/**
@ -24,6 +25,20 @@ class NaviUtils private constructor(){
AmapNaviParams(null, null, Poi(startName, latLng, ""), AmapNaviType.DRIVER),
object : MyINaviInfoCallback() {}
)
// val params = AmapNaviParams(
// Poi("北京站", latLng, ""),
// null,
// Poi("故宫博物院", LatLng(39.917337, 116.397056), ""),
// AmapNaviType.DRIVER
// )
// params.setUseInnerVoice(true)
// AmapNaviPage.getInstance().showRouteActivity(
// context, params, object : MyINaviInfoCallback() {},
// CustomAmapRouteActivity::class.java
// )
}
fun getRoute(context: Context,startLatLng: LatLng,endLatLng: LatLng,startName:String = "",endName:String = ""){

View File

@ -164,7 +164,7 @@ class OrderUtils private constructor() {
.subscribe(BaseObserver(context, object : RxHttpCallBack<OrderDetailBean>() {
override fun onSuccess(t: CommonResponseBean<OrderDetailBean>) {
super.onSuccess(t)
if (t.data != null) {
if (t.data != null&&!t.data.orderId.isNullOrEmpty()) {
BaseSPUtils.put(context, NEED_UP_ORDER, Gson().toJson(t.data))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(Intent(context, UpLocationService2::class.java))

View File

@ -0,0 +1,28 @@
package com.dahe.gldriver.weight.overlay
import android.os.Bundle
import android.os.PersistableBundle
import com.amap.api.navi.AmapRouteActivity
/**
*
* @author liqi
* @date 2019/2/22
*/
class CustomAmapRouteActivity : AmapRouteActivity() {
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
}
override fun onResume() {
super.onResume()
}
override fun onPause() {
super.onPause()
}
override fun onDestroy() {
super.onDestroy()
}
}

View File

@ -0,0 +1,312 @@
package com.dahe.gldriver.weight.overlay
import android.content.Context
import android.graphics.Color
import com.amap.api.maps.AMap
import com.amap.api.maps.model.BitmapDescriptorFactory
import com.amap.api.maps.model.LatLng
import com.amap.api.maps.model.LatLngBounds
import com.amap.api.maps.model.Marker
import com.amap.api.maps.model.PolylineOptions
import com.amap.api.services.core.LatLonPoint
import com.amap.api.services.route.DrivePath
import com.amap.api.services.route.TMC
import com.dahe.gldriver.R
/**
* 导航路线图层类
*/
class DrivingRouteOverlay(
private val mContext: Context, amap: AMap, path: DrivePath?,
start: LatLonPoint, end: LatLonPoint, throughPointList: List<LatLonPoint>?
) : RouteOverlay(
mContext
) {
private val drivePath: DrivePath?
private val throughPointList: List<LatLonPoint>?
private val throughPointMarkerList: MutableList<Marker>? = ArrayList()
private var throughPointMarkerVisible = true
private var tmcs: MutableList<TMC>? = null
private var mPolylineOptions: PolylineOptions? = null
private var mPolylineOptionscolor: PolylineOptions? = null
private var isColorfulline = true
/**
* 设置路线宽度
*
* @param mWidth 路线宽度取值范围大于0
*/
override var routeWidth = 25f
private var mLatLngsOfPath: MutableList<LatLng>? = null
fun setIsColorfulline(iscolorfulline: Boolean) {
isColorfulline = iscolorfulline
}
/**
* 根据给定的参数构造一个导航路线图层类对象
*
* @param amap 地图对象
* @param path 导航路线规划方案
* @param context 当前的activity对象
*/
init {
mAMap = amap
drivePath = path
startPoint = LatLng(start.latitude, start.longitude)
endPoint = LatLng(end.latitude, end.longitude)
this.throughPointList = throughPointList
}
/**
* 添加驾车路线添加到地图上显示
*/
fun addToMap() {
initPolylineOptions()
try {
if (mAMap == null) {
return
}
if (routeWidth == 0f || drivePath == null) {
return
}
mLatLngsOfPath = ArrayList()
tmcs = ArrayList()
val drivePaths = drivePath.steps
for (step in drivePaths) {
val latlonPoints = step.polyline
val tmclist = step.tmCs
tmcs?.addAll(tmclist)
// addDrivingStationMarkers(step, convertToLatLng(latlonPoints.get(0)));
for (latlonpoint in latlonPoints) {
mPolylineOptions!!.add(convertToLatLng(latlonpoint))
mLatLngsOfPath?.add(convertToLatLng(latlonpoint))
}
}
if (startMarker != null) {
startMarker!!.remove()
startMarker = null
}
if (endMarker != null) {
endMarker!!.remove()
endMarker = null
}
addStartAndEndMarker()
// addThroughPointMarker();
if (isColorfulline && tmcs?.size!! > 0) {
colorWayUpdate(tmcs)
showcolorPolyline()
} else {
showPolyline()
}
} catch (e: Throwable) {
e.printStackTrace()
}
}
/**
* 初始化线段属性
*/
private fun initPolylineOptions() {
mPolylineOptions = null
mPolylineOptions = PolylineOptions()
mPolylineOptions!!
.color(driveColor)
.setCustomTexture(BitmapDescriptorFactory.fromResource(R.drawable.icon_roud_type))
.width(routeWidth)
}
private fun showPolyline() {
addPolyLine(mPolylineOptions)
}
private fun showcolorPolyline() {
addPolyLine(mPolylineOptionscolor)
}
/**
* 根据不同的路段拥堵情况展示不同的颜色
*
* @param tmcSection
*/
private fun colorWayUpdate(tmcSection: List<TMC>?) {
if (mAMap == null) {
return
}
if (tmcSection == null || tmcSection.size <= 0) {
return
}
var segmentTrafficStatus: TMC
mPolylineOptionscolor = null
mPolylineOptionscolor = PolylineOptions()
mPolylineOptionscolor!!.width(routeWidth)
val colorList: MutableList<Int> = ArrayList()
val start = tmcSection[0].polyline[0]
mPolylineOptionscolor!!.add(LatLng(start.latitude, start.longitude))
colorList.add(driveColor)
for (i in tmcSection.indices) {
segmentTrafficStatus = tmcSection[i]
val color = getcolor(segmentTrafficStatus.status)
val mployline = segmentTrafficStatus.polyline
for (j in 1 until mployline.size) {
mPolylineOptionscolor!!.add(LatLng(mployline[j].latitude, mployline[j].longitude))
colorList.add(color)
}
}
colorList.add(driveColor)
mPolylineOptionscolor!!.colorValues(colorList)
}
private fun getcolor(status: String): Int {
return if (status == "畅通") {
Color.GREEN
} else if (status == "缓行") {
Color.YELLOW
} else if (status == "拥堵") {
Color.RED
} else if (status == "严重拥堵") {
Color.parseColor("#990033")
} else {
Color.parseColor("#537edc")
}
}
fun convertToLatLng(point: LatLonPoint): LatLng {
return LatLng(point.latitude, point.longitude)
}
override val latLngBounds: LatLngBounds
// /**
protected get() {
val b = LatLngBounds.builder()
b.include(LatLng(startPoint!!.latitude, startPoint!!.longitude))
b.include(LatLng(endPoint!!.latitude, endPoint!!.longitude))
if (throughPointList != null && throughPointList.size > 0) {
for (i in throughPointList.indices) {
b.include(
LatLng(
throughPointList[i].latitude,
throughPointList[i].longitude
)
)
}
}
return b.build()
}
fun setThroughPointIconVisibility(visible: Boolean) {
try {
throughPointMarkerVisible = visible
if (throughPointMarkerList != null
&& throughPointMarkerList.size > 0
) {
for (i in throughPointMarkerList.indices) {
throughPointMarkerList[i].isVisible = visible
}
}
} catch (e: Throwable) {
e.printStackTrace()
}
}
/**
* 去掉DriveLineOverlay上的线段和标记
*/
override fun removeFromMap() {
try {
super.removeFromMap()
if (throughPointMarkerList != null
&& throughPointMarkerList.size > 0
) {
for (i in throughPointMarkerList.indices) {
throughPointMarkerList[i].remove()
}
throughPointMarkerList.clear()
}
} catch (e: Throwable) {
e.printStackTrace()
}
}
companion object {
/**
* 途径点
*/
// private void addThroughPointMarker() {
// if (this.throughPointList != null && this.throughPointList.size() > 0) {
// LatLonPoint latLonPoint = null;
// for (int i = 0; i < this.throughPointList.size(); i++) {
// latLonPoint = this.throughPointList.get(i);
// if (latLonPoint != null) {
// throughPointMarkerList.add(mAMap
// .addMarker((new MarkerOptions())
// .position(
// new LatLng(latLonPoint
// .getLatitude(), latLonPoint
// .getLongitude()))
// .visible(throughPointMarkerVisible)
// .icon(getThroughPointBitDes())
// .title("\u9014\u7ECF\u70B9")));
// }
// }
// }
// }
/**
* 途径点
* @return
*/
// private BitmapDescriptor getThroughPointBitDes() {
// return BitmapDescriptorFactory.fromResource(R.drawable.amap_through);
//
// }
/**
* 获取两点间距离
*
* @param start
* @param end
* @return
*/
fun calculateDistance(start: LatLng, end: LatLng): Int {
val x1 = start.longitude
val y1 = start.latitude
val x2 = end.longitude
val y2 = end.latitude
return calculateDistance(x1, y1, x2, y2)
}
fun calculateDistance(x1: Double, y1: Double, x2: Double, y2: Double): Int {
var x1 = x1
var y1 = y1
var x2 = x2
var y2 = y2
val NF_pi = 0.01745329251994329 // 弧度 PI/180
x1 *= NF_pi
y1 *= NF_pi
x2 *= NF_pi
y2 *= NF_pi
val sinx1 = Math.sin(x1)
val siny1 = Math.sin(y1)
val cosx1 = Math.cos(x1)
val cosy1 = Math.cos(y1)
val sinx2 = Math.sin(x2)
val siny2 = Math.sin(y2)
val cosx2 = Math.cos(x2)
val cosy2 = Math.cos(y2)
val v1 = DoubleArray(3)
v1[0] = cosy1 * cosx1 - cosy2 * cosx2
v1[1] = cosy1 * sinx1 - cosy2 * sinx2
v1[2] = siny1 - siny2
val dist = Math.sqrt(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2])
return (Math.asin(dist / 2) * 12742001.5798544).toInt()
}
//获取指定两点之间固定距离点
fun getPointForDis(sPt: LatLng, ePt: LatLng, dis: Double): LatLng {
val lSegLength = calculateDistance(sPt, ePt).toDouble()
val preResult = dis / lSegLength
return LatLng(
(ePt.latitude - sPt.latitude) * preResult + sPt.latitude,
(ePt.longitude - sPt.longitude) * preResult + sPt.longitude
)
}
}
}

View File

@ -0,0 +1,206 @@
package com.dahe.gldriver.weight.overlay
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Color
import com.amap.api.maps.AMap
import com.amap.api.maps.CameraUpdateFactory
import com.amap.api.maps.model.BitmapDescriptor
import com.amap.api.maps.model.BitmapDescriptorFactory
import com.amap.api.maps.model.LatLng
import com.amap.api.maps.model.LatLngBounds
import com.amap.api.maps.model.Marker
import com.amap.api.maps.model.MarkerOptions
import com.amap.api.maps.model.Polyline
import com.amap.api.maps.model.PolylineOptions
import com.dahe.gldriver.R
open class RouteOverlay(private val mContext: Context) {
protected var stationMarkers: MutableList<Marker>? = ArrayList()
protected var allPolyLines: MutableList<Polyline> = ArrayList()
protected var startMarker: Marker? = null
protected var endMarker: Marker? = null
protected var startPoint: LatLng? = null
protected var endPoint: LatLng? = null
protected var mAMap: AMap? = null
private var startBit: Bitmap? = null
private var endBit: Bitmap? = null
private var busBit: Bitmap? = null
private var walkBit: Bitmap? = null
private var driveBit: Bitmap? = null
protected var nodeIconVisible = true
/**
* 去掉BusRouteOverlay上所有的Marker
* @since V2.1.0
*/
open fun removeFromMap() {
if (startMarker != null) {
startMarker!!.remove()
}
if (endMarker != null) {
endMarker!!.remove()
}
for (marker in stationMarkers!!) {
marker.remove()
}
for (line in allPolyLines) {
line.remove()
}
destroyBit()
}
private fun destroyBit() {
if (startBit != null) {
startBit!!.recycle()
startBit = null
}
if (endBit != null) {
endBit!!.recycle()
endBit = null
}
if (busBit != null) {
busBit!!.recycle()
busBit = null
}
if (walkBit != null) {
walkBit!!.recycle()
walkBit = null
}
if (driveBit != null) {
driveBit!!.recycle()
driveBit = null
}
}
protected val startBitmapDescriptor: BitmapDescriptor
/**
* 给起点Marker设置图标并返回更换图标的图片如不用默认图片需要重写此方法
* @return 更换的Marker图片
* @since V2.1.0
*/
protected get() = BitmapDescriptorFactory.fromResource(R.drawable.icon_loca_load)
protected val endBitmapDescriptor: BitmapDescriptor
/**
* 给终点Marker设置图标并返回更换图标的图片如不用默认图片需要重写此方法
* @return 更换的Marker图片
* @since V2.1.0
*/
protected get() = BitmapDescriptorFactory.fromResource(R.drawable.icon_loca_unload)
/**
* 给公交Marker设置图标并返回更换图标的图片如不用默认图片需要重写此方法
* @return 更换的Marker图片
* @since V2.1.0
*/
// protected BitmapDescriptor getBusBitmapDescriptor() {
// return BitmapDescriptorFactory.fromResource(R.drawable.amap_bus);
// }
/**
* 给步行Marker设置图标并返回更换图标的图片如不用默认图片需要重写此方法
* @return 更换的Marker图片
* @since V2.1.0
*/
// protected BitmapDescriptor getWalkBitmapDescriptor() {
// return BitmapDescriptorFactory.fromResource(R.drawable.amap_man);
// }
// protected BitmapDescriptor getDriveBitmapDescriptor() {
// return BitmapDescriptorFactory.fromResource(R.drawable.amap_car);
// }
protected fun addStartAndEndMarker() {
startMarker = mAMap!!.addMarker(
MarkerOptions()
.position(startPoint).icon(startBitmapDescriptor)
.title("\u8D77\u70B9")
)
// startMarker.showInfoWindow();
endMarker = mAMap!!.addMarker(
MarkerOptions().position(endPoint)
.icon(endBitmapDescriptor).title("\u7EC8\u70B9")
)
// mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(startPoint,
// getShowRouteZoom()));
}
/**
* 移动镜头到当前的视角
* @since V2.1.0
*/
fun zoomToSpan() {
if (startPoint != null) {
if (mAMap == null) {
return
}
try {
val bounds = latLngBounds
mAMap!!.animateCamera(
CameraUpdateFactory
.newLatLngBounds(bounds, 100)
)
} catch (e: Throwable) {
e.printStackTrace()
}
}
}
protected open val latLngBounds: LatLngBounds
protected get() {
val b = LatLngBounds.builder()
b.include(LatLng(startPoint!!.latitude, startPoint!!.longitude))
b.include(LatLng(endPoint!!.latitude, endPoint!!.longitude))
return b.build()
}
/**
* 路段节点图标控制显示接口
* @param visible true为显示节点图标false为不显示
* @since V2.3.1
*/
fun setNodeIconVisibility(visible: Boolean) {
try {
nodeIconVisible = visible
if (stationMarkers != null && stationMarkers!!.size > 0) {
for (i in stationMarkers!!.indices) {
stationMarkers!![i].isVisible = visible
}
}
} catch (e: Throwable) {
e.printStackTrace()
}
}
protected fun addStationMarker(options: MarkerOptions?) {
if (options == null) {
return
}
val marker = mAMap!!.addMarker(options)
if (marker != null) {
stationMarkers!!.add(marker)
}
}
protected fun addPolyLine(options: PolylineOptions?) {
if (options == null) {
return
}
val polyline = mAMap!!.addPolyline(options)
if (polyline != null) {
allPolyLines.add(polyline)
}
}
protected open val routeWidth: Float
protected get() = 18f
protected val walkColor: Int
protected get() = Color.parseColor("#6db74d")
protected val busColor: Int
/**
* 自定义路线颜色
* return 自定义路线颜色
* @since V2.2.1
*/
protected get() = Color.parseColor("#537edc")
protected val driveColor: Int
protected get() = Color.parseColor("#537edc") // protected int getShowRouteZoom() {
// return 15;
// }
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -313,6 +313,7 @@
android:textStyle="bold" />
<LinearLayout
android:id="@+id/llRoutes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"