我的函数成功呈现了从起点到终点的路线:
private fun renderRouteToDestination(){
val origin = Point.fromLngLat(initialLocation!!.longitude, initialLocation!!.latitude)
val destination = Point.fromLngLat(143.152001, -37.260811)
val navRoute = NavigationRoute.builder(context)
.accessToken(getString(R.string.mapbox_access_token))
.origin(origin)
.profile(DirectionsCriteria.PROFILE_WALKING)
.destination(destination)
.build()
navRoute.getRoute(object : Callback<DirectionsResponse> {
override fun onFailure(call: Call<DirectionsResponse>, t: Throwable) {}
override fun onResponse(call: Call<DirectionsResponse>, response: Response<DirectionsResponse>) {
val routeResponse = response ?: return
val body = routeResponse.body() ?: return
if (body.routes().count() == 0){
Log.d(TAG, "There were no routes")
return
}
if (navigationMapRoute != null) navigationMapRoute?.updateRouteVisibilityTo(false)
navigationMapRoute = NavigationMapRoute(null, mapView!!, mapbox)
val directionsRoute = body.routes().first()
navigationMapRoute?.addRoute(directionsRoute)
Log.d(TAG, "Successful got route to destination")
}
})
}
但是我想通过两种方式自定义路线:
更改路线的颜色
用虚线代替实线
如何实现这些样式?
答案 0 :(得分:0)
Android Nav SDK文档在此处详细介绍了有关如何修改路线的样式默认设置的详细信息:https://docs.mapbox.com/android/navigation/overview/map-styling/#style-the-map-route
最重要的是,您可以在初始化NavigationMapRoute
———
⚠️免责声明:我目前在Mapbox⚠️
工作