我按照MapBox documentation中的示例实现了自定义NavigationActivity,到目前为止,它可以将导航UI显示为地图,但无法启动导航本身,也无法显示用户的位置。通过NavigationFragment实现它时,存在相同的问题。 从MainActivity调用NavigationActivity / NavigationFragment并正确启动逐行导航时,如何传递丢失的信息?
非常感谢您的帮助!
我创建了DirectionsRoute,并使用NavigationViewOptions.builder()调用NavigationView.startNavigation(options),如下所示:
override private fun onNavigationReady() {
...
calculateRoute(origin, destination)
}
private fun calculateRoute(origin: Point , destination: Point) {
NavigationRoute.builder(this.context)
.accessToken(Mapbox.getAccessToken()!!)
.origin(origin)
.destination(destination)
.build()
.getRoute( object : Callback<DirectionsResponse> {
// Send request to Direction API
override fun onFailure(call: Call<DirectionsResponse>? , t: Throwable?) {
}
override fun onResponse(call: Call<DirectionsResponse>? ,
response: Response<DirectionsResponse>?) {
if (response?.body() == null || response.body()?.routes()?.size!! < 1) {
return
}
directionsRoute = response.body()!!.routes()[0]
startNavigation()
}
})
}
private fun startNavigation() {
if (directionsRoute == null) return
val options = NavigationViewOptions.builder()
.directionsRoute(directionsRoute)
.shouldSimulateRoute(true)
.navigationListener(this)
.build()
navigationView.startNavigation(options)
}