问题描述
我正在开发一个具有跟踪GPS位置以绘制地图的功能的应用程序.
I'm working on an application that has a feature in which GPS position is tracked to draw a map.
基本上,每秒我将一个点(包含纬度和经度以及其他信息)保存到数组中,然后每15秒将数组保存到数据库中一次,并将所有信息发送到服务器一次旅行结束了.
Essentially, every second, I am saving a point (containing latitude and longitude, as well as other info) to an array, then every 15 seconds I save the array to my database, and send all the info to the server once the trip is over.
我每秒使用Location.getLatitude()和Location.getLongitude()获取位置.但是,在旅行后查看发送到服务器的文件时,经度和纬度仅每100到300秒更改一次(在汽车中记录,因此应该更频繁地更改)-在9公里的旅行中,花了24分钟,我只记录了8个不同的纬度/经度组合(包括开始和结束)
I get the location each second using Location.getLatitude() and Location.getLongitude(). However, when looking at the file sent to the server after a trip, the longitude and latitude only change every 100 to 300 seconds (recording while in a car, so it should be changing a lot more often) - on a 9km trip, which took 24 minutes, I only have 8 different latitude/longitude combos recorded (including start and finish)
我在这些点中记录的其他内容正在每秒更新一次,因此这纯粹是一个经度/纬度问题.
Other things I'm recording in the points are being updated each second as they should, so it's purely a longitude/latitude problem.
我是否需要做一些操作才能使location.getLongitude()更新得更频繁?或者另外一种获取经度/纬度的方法会更好
Is there something I need to do for location.getLongitude() to update more frequently? Or another way of getting longitude/latitude that would work better
谢谢
推荐答案
创建位置请求时,请将间隔和最快间隔设置为较小的数字.像这样:
When creating your location request set interval and fastest interval to a smaller number. Something like this:
private val UPDATE_INTERVAL = (30 * 1000).toLong() /* 30 secs */
private val FASTEST_INTERVAL: Long = 10000 /* 10 sec */
然后创建您的locationRequest:
And then create your locationRequest:
locationRequest = LocationRequest.create()
locationRequest.interval = UPDATE_INTERVAL
locationRequest.fastestInterval = FASTEST_INTERVAL
locationRequest.priority = LocationRequest.PRIORITY_HIGH_ACCURACY
这篇关于location.getlongitude()和getlatitude()仅每100-300秒更新一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!