【问题标题】:Get user location at high speed高速获取用户位置
【发布时间】:2019-12-05 14:36:45
【问题描述】:

我一直在使用 MapBox 绘制地图,并在地图上表示用户位置。在使用位置引擎的同时,我订阅了位置更改。位置更改的问题在于它们每秒发生一次(最多),而我的用户大多是开车,所以记录的位置往往落后。

我意识到即使记录的位置在后面,显示用户当前位置的标记似乎总是准确的。我想知道是否有可能获得当前位置标记的“估计”位置。

此外,根据 mapbox 的文档,我可以使用 ProgressChangeListener 获得更准确的位置(也更频繁)。我试过这样设置,但没有用。

val nav = MapboxNavigation(this,getString(R.string.access_token))
    nav.addProgressChangeListener { location, routeProgress ->
        Timber.tag("GPSDEBUG").d("GOT LOC UPDATE on ${System.currentTimeMillis()} with ${location.longitude},${location.latitude}")
    }
    nav.startNavigation(DirectionsRoute.fromJson(""))

显然 MapBox 不喜欢空路或虚假导航。

在我尝试其他建议(例如使用卡尔曼算法来“估计”缺失的位置)之前,如果能得到反馈,我会很高兴。

最终:主要目标是即使在高速下也能检索准确的 GPS 坐标。

【问题讨论】:

  • 你想得到用户的准确位置,对吧?
  • @GunduBandgar 是的,速度非常快
  • @Yeheshuah 更快的路线允许用户检测到比最初计算的路线更快(流量更少)的新路线。与速度更快时获取当前准确位置无关
  • @113408 你找到解决办法了吗?

标签: android gps mapbox


【解决方案1】:

我的解决方案是计算点 A 和点 B 之间的缺失位置,因为知道 GPS 提供更新的最大速率是 1 秒。在现实生活中,当人们在高速公路上高速行驶时,我不得不扣 3 到 4 分。

private fun processMissingPoints() {
    val stepInMeters = lastUsedLocation.distanceTo(lastKnownLocation) / (numberOfMissingPoints).toDouble()
    val bearing = lastUsedLocation.bearingTo(lastKnownLocation)
    missingPoints.forEach{ point ->
        val newCoordinates = getNewCoordinates(lastUsedLocation.latitude , lastUsedLocation.longitude,stepInMeters*(index+1), bearing.toDouble())
    }
}


/**
 * http://www.movable-type.co.uk/scripts/latlong.html#dest-point
 * Given a start point, initial bearing, and distance, this will calculate the destination
 * point and final bearing travelling along a (shortest distance) great circle arc.
 */
private fun getNewCoordinates(latitude: Double,longitude: Double,distanceInMetres: Double,bearing: Double) : LatLng{
    val brngRad = toRadians(bearing)
    val latRad = toRadians(latitude)
    val lonRad = toRadians(longitude)
    val earthRadiusInMetres = 6371000
    val distFrac = distanceInMetres / earthRadiusInMetres

    val latitudeResult = asin(sin(latRad) * cos(distFrac) + cos(latRad) * sin(distFrac) * cos(brngRad))
    val a = atan2(sin(brngRad) * sin(distFrac) * cos(latRad), cos(distFrac) - sin(latRad) * sin(latitudeResult))
    val longitudeResult = (lonRad + a + 3 * PI) % (2 * PI) - PI

    return LatLng(toDegrees(latitudeResult),toDegrees(longitudeResult))
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多