高速获取用户位置

问题描述 投票:3回答:1

我一直在使用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不喜欢空路或假导航。

在我尝试其他建议之前,如使用卡尔曼算法来 "估计 "丢失的位置,如果能得到一个反馈,那就太好了。

ULTIMATELY。 主要的目标是在高速行驶的情况下 也能检索到准确的GPS坐标。

android gps mapbox
1个回答
0
投票

我的解决方案是计算点A和点B之间的缺失位置,知道GPS给出的更新的最大速率是1s。在实际生活中,当人们在高速公路上高速行驶时,我不得不扣除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))
}
© www.soinside.com 2019 - 2024. All rights reserved.