You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在HERE SDK(导航版)中获取安全摄像头坐标及实时距离回调

解决方案:获取安全摄像头坐标与实时距离更新

针对你使用HERE SDK v4.12.11.x遇到的问题,提供两种可行方案:

一、直接获取安全摄像头坐标

你当前使用的SafetyCameraWarning对象本身就包含摄像头的地理坐标属性,只需直接调用coordinates即可获取,无需额外操作:

visualNavigator.setSafetyCameraWarningListener { safetyCameraWarning ->
    // 获取摄像头剩余距离
    val distance = safetyCameraWarning.distanceToCameraInMeters
    // 获取摄像头经纬度坐标
    val cameraCoords = safetyCameraWarning.coordinates
    // 后续可基于坐标做自定义逻辑,比如存储或显示位置
}

二、实现实时距离更新(替代单次回调)

由于SafetyCameraWarningListener仅在特定时机触发,若要像官方APP那样实时更新剩余距离,可结合位置更新监听器实现:

  1. 先通过摄像头监听器缓存当前目标摄像头的坐标
  2. 在位置更新回调中,实时计算当前定位点到缓存坐标的距离

示例代码:

// 缓存当前待经过的安全摄像头坐标
var targetCameraCoords: GeoCoordinates? = null

// 监听安全摄像头,缓存目标坐标
visualNavigator.setSafetyCameraWarningListener { warning ->
    targetCameraCoords = warning.coordinates
    // 记录初始触发时的距离
    val initialDistance = warning.distanceToCameraInMeters
}

// 监听实时位置更新,计算实时距离
visualNavigator.positionUpdatedListener = { positionEvent ->
    targetCameraCoords?.let { cameraCoords ->
        val currentPos = positionEvent.position.coordinates
        // 计算两点直线距离(若需路径精准距离,可基于Route做分段计算)
        val realTimeDistance = currentPos.distanceTo(cameraCoords)
        // 更新UI显示实时剩余距离
    }
}

注意:车辆经过摄像头后,记得清空targetCameraCoords,避免计算无效距离。

如果需要提前获取路径上所有安全摄像头信息,可在路线规划完成后,遍历Route的sections提取所有摄像头数据:

// 假设已获取规划好的Route对象
val allRouteCameras = mutableListOf<SafetyCamera>()
route.sections.forEach { section ->
    section.safetyCameras?.let { allRouteCameras.addAll(it) }
}

之后可结合实时位置,筛选出当前未经过的摄像头,计算最近的那个的剩余距离。

内容的提问来源于stack exchange,提问作者Javier

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 01:50:26