gpt4 book ai didi

android - 高速获取用户位置

转载 作者:行者123 更新时间:2023-12-05 00:05:27 29 4
gpt4 key购买 nike

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

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

此外,根据 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 坐标。

最佳答案

我的解决方案是计算点 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))
}

关于android - 高速获取用户位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59197472/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com