我想在要求在地图片段上绘制路线时在android上的提示消息上显示“总行程持续时间”,如图所示。 Total trip duration
答案 0 :(得分:0)
您可以使用信息提示框显示旅行总时长。阅读更多信息的文档:https://developer.here.com/documentation/maps/topics/map-controls.html
信息气泡
除了地图控件之外,UI模块还支持信息提示框。信息气泡可让您从字面上显示出包含HTML内容(例如文本或图像)的“气泡”。
以下代码通过向地图显示中添加信息提示框来扩展本文的第一个示例。它创建一个InfoBubble实例,并指定该实例应出现的位置的地理坐标以及HTML内容,在本例中为文本字符串“ Hello World!”。粗体。最后一行将信息提示对象添加到UI实例。
// Create an info bubble object at a specific geographic location:
var bubble = new H.ui.InfoBubble({ lng: 13.4, lat: 52.51 }, {
content: '<b>Hello World!</b>'
});
// Add info bubble to the UI:
ui.addBubble(bubble);
要获取总行程费用,请致电路由API并获取摘要信息。https://developer.here.com/documentation/android-premium/dev_guide/topics/routing.html
答案 1 :(得分:0)
这是一个示例代码,可用于呈现2个位置,源和目的地,其路线以及在路线中间的标记。您必须替换源和目标位置的图像,并为气泡添加注释中的链接,以使用显示计算出的距离(包括正在进行的交通)的文本生成位图(或其他在线指南)。
private fun renderLocations() {
val locations = arrayOf(
GeoCoordinate(37.4219999, -122.0862462),
GeoCoordinate(33.9880667, -118.4854341)
)
val sourceMarker = MapMarker(locations[0], Image().apply {
try {
// set source marker image
setImageResource(android.R.drawable.ic_menu_compass)
} catch (throwable: Throwable) { }
})
val destinationMarker = MapMarker(locations[1], Image().apply {
try {
// set destination marker image
setImageResource(android.R.drawable.ic_menu_camera)
} catch (throwable: Throwable) { }
})
map.addMapObjects(listOf(sourceMarker, destinationMarker))
calculateRoute(locations[0], locations[1])
}
private fun calculateRoute(source: GeoCoordinate, destination: GeoCoordinate) {
CoreRouter().apply {
dynamicPenalty = DynamicPenalty().apply {
trafficPenaltyMode = Route.TrafficPenaltyMode.OPTIMAL
}
calculateRoute(
RoutePlan().apply {
routeOptions = RouteOptions().apply {
transportMode = RouteOptions.TransportMode.CAR
setHighwaysAllowed(true)
routeType = RouteOptions.Type.SHORTEST // other alternatives: FASTEST, BALANCED
routeCount = 1
}
addWaypoint(RouteWaypoint(source))
addWaypoint(RouteWaypoint(destination))
}, object : Router.Listener<List<RouteResult>, RoutingError> {
override fun onCalculateRouteFinished(p0: List<RouteResult>?, p1: RoutingError?) {
p1?.let {
if (it == RoutingError.NONE) {
p0?.let { result ->
if (result.isNotEmpty()) {
// I only show the first result, maybe you want to show all routes
val routeResult = result[0].route
val durationWithDelayInSeconds = routeResult.getTtaIncludingTraffic(Route.WHOLE_ROUTE).duration
val totalWayPoints = routeResult.routeGeometry?.size
val middlePoint: GeoCoordinate? = routeResult.routeGeometry?.get(totalWayPoints!! / 2)
middlePoint?.let {
map.addMapObject(MapMarker(it/*, Image().apply {
// Draw yourbitmap. A good resource can be found here: https://medium.com/@travells2323/android-draw-text-to-bitmap-8251f6d79150
}*/
))
}
mapRoute?.let {
map.removeMapObject(it)
}
mapRoute = null
mapRoute = MapRoute(routeResult)
mapRoute?.let {
map.addMapObject(it)
it.renderType = MapRoute.RenderType.USER_DEFINED
it.color = Color.BLUE
it.isTrafficEnabled = true
}
}
}
}
}
}
override fun onProgress(p0: Int) {
/* The calculation progress can be retrieved in this callback. */
}
})
}
}
以上代码的最终结果为
用所需的图像替换图像后,您将获得想要的最终结果。