Android GPS更新频率 [英] Android GPS update frequency

查看:1247
本文介绍了Android GPS更新频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写圈计时应用程序,但遇到了GPS更新频率问题。在速度大于75km / h(21m / s)时,我的代码停止工作。我的问题是如何以更快的速度请求更新?我需要它以高达300km / h(83m / s)的速度工作,并希望应用程序每行驶几米就能获得更新,这意味着它需要每0.025秒@ 300km / h更新一次。下面是我的代码,我尝试了一个替代代码来获取时间戳,但得到了相同的结果,我相信这是一个GPS更新频率问题,而不是代码问题。我想每隔300米测量几米,以防手机通过切线上的接近半径。

  int prox = 30; //接近开关至终点线= 30米
int speedGov = 0; //速度以Kmh为单位

public void OnProviderDisabled(string provider)
{
}

public void OnProviderEnabled(string provider)
{

$ b $ public void OnStatusChanged(String provider,Availability status,Bundle extras)
{
}

protected override void OnResume()
{
this.InitializeLocationManager();
base.OnResume();
_locationManager.RequestLocationUpdates(_locationProvider,0,0,this);


void InitializeLocationManager()
{
_locationManager =(LocationManager)GetSystemService(LocationService);
Criteria criteriaForLocationService = new Criteria
{
Accuracy = Accuracy.Fine
};
IList< string> acceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService,true);
if(acceptableLocationProviders.Any())
{
_locationProvider = acceptableLocationProviders.First();
}
else
{
_locationProvider = String.Empty;
}
}

public void OnLocationChanged(Location location)
{
_currentLocation = location;
if(_currentLocation == null)
{
}
else
{
d2fl = Convert.ToInt32(_currentLocation.DistanceTo(fl));
speedGov = Convert.ToInt32(_currentLocation.Speed * 3.6);
}
}

int A = 0; //第一个距离到终点线
int B = 1000000; //第二距离到终点线

//获取时间戳
while(true)
{
A = d2fl;
if(A>& d2fl< prox& speedGov> 2)//远离终点线&距终点线30m以内速度超过2公里/小时
{
//手机第一次开始远离终点线时的时间戳
string hours = DateTime.Now.ToString(HH);
string minutes = DateTime.Now.ToString(mm);
string seconds = DateTime.Now.ToString(ss);
string milliseconds = DateTime.Now.ToString(fff);
lapFinishTimeStamp =(Convert.ToDecimal(hours)* 3600)+(Convert.ToDecimal(minutes)* 60)+ Convert.ToDecimal(seconds)+(Convert.ToDecimal(milliseconds)/ 1000);
A = 0;
B = 1000000;
休息;
}
B = A;
}

//交替获取时间戳 - 与上面的工作相同获取时间戳
while(true)
{
int A = d2fl;
Thread.Sleep(5);
int B = d2fl; (A< B& d2fl< prox& speedGov> 2)
{
string hours = DateTime.Now.ToString(HH);
string minutes = DateTime.Now.ToString(mm);
string seconds = DateTime.Now.ToString(ss);
string milliseconds = DateTime.Now.ToString(fff);
lapFinishTimeStamp =(Convert.ToDecimal(hours)* 3600)+(Convert.ToDecimal(minutes)* 60)+ Convert.ToDecimal(seconds)+(Convert.ToDecimal(milliseconds)/ 1000);
A = 0;
B = 0;
休息;
}
A = 0;
B = 0;
}

在这个论坛上读过一些其他的图片,但已经有几年了。此应用程序将需要在Galaxy S4以上工作。

另外,我对GPS频率有点困惑,从我读过的GPS频率在相当(硬件约为1.6 GHz),但手机操作系统似乎将数据剔除的频率较低,这是有意为之?

解决方案

不要混淆无线电频率值(1.1-1.6GHz)与频率的更新频率(1Hz)。

你见过设备列表:以精确的时间间隔获取GPS位置 ?尽管它几年前,我怀疑任何设备上的GPS都会报告更快(可能是由于电池/噪音/用例设计)。即使车载设备以10Hz或20Hz报告,仅为100ms或50ms,仍然比25ms的要求慢。请记住,如果CPU正在与GPS通话并计算位置 - 它正在吃电池,这是移动设备上的限制因素。



如果您希望获得一致的亚秒级GPS值更新,您需要使用外部设备。


I'm writing a lap timing app but have run into a GPS update frequency problem. At speeds greater than 75km/h (21m/s) my code stops working. My question is how can I request updates at a faster rate? I need it work at speeds up to 300km/h (83m/s) and would like the app to get updates every couple of meters traveled which would mean it would need an update every 0.025 seconds @ 300km/h. Below is my code, I tried an alternate code to get time stamp but got the same result, I believe it's a GPS update frequency problem not a code problem. I wanted updates every couple of meters @ 300km/h in case the phone passes through the proximity radius on a tangent.

int prox = 30;      // Proximity Switch To Finish Line = 30 meters
int speedGov = 0;   // Speed In Kmh

public void OnProviderDisabled(string provider)
{
}

public void OnProviderEnabled(string provider)
{
}

public void OnStatusChanged(string provider, Availability status, Bundle extras)
{
}

protected override void OnResume()
{
    this.InitializeLocationManager();
    base.OnResume();
    _locationManager.RequestLocationUpdates(_locationProvider, 0, 0, this);
}

void InitializeLocationManager()
{
    _locationManager = (LocationManager)GetSystemService(LocationService);
    Criteria criteriaForLocationService = new Criteria
    {
        Accuracy = Accuracy.Fine
    };
    IList<string> acceptableLocationProviders =     _locationManager.GetProviders(criteriaForLocationService, true);
    if (acceptableLocationProviders.Any())
    {
        _locationProvider = acceptableLocationProviders.First();
    }
    else
    {
        _locationProvider = String.Empty;
    }
}

public void OnLocationChanged(Location location)
{
    _currentLocation = location;
    if (_currentLocation == null)
    {
    }
    else
    {
        d2fl = Convert.ToInt32(_currentLocation.DistanceTo(fl));
        speedGov = Convert.ToInt32(_currentLocation.Speed * 3.6);
    }
}

int A = 0;      // 1st Distance to Finish Line
int B = 1000000;    // 2nd Distance to Finish Line

// Get Time Stamp
while (true)
{
    A = d2fl;
    if (A > B && d2fl < prox && speedGov > 2)   // Travelling away from Finish Line & Within 30m proximity to Finish Line & Going faster than 2km/h
    {
        // Time stamp for when phone first starts travelling away from Finish Line
        string hours = DateTime.Now.ToString("HH");
        string minutes = DateTime.Now.ToString("mm");
        string seconds = DateTime.Now.ToString("ss");
        string milliseconds = DateTime.Now.ToString("fff");
        lapFinishTimeStamp = (Convert.ToDecimal(hours) * 3600) + (Convert.ToDecimal(minutes) * 60) + Convert.ToDecimal(seconds) + (Convert.ToDecimal(milliseconds) / 1000);
        A = 0;
        B = 1000000;
        break;
    }
    B = A;
}

// Alternate Get Time Stamp - worked the same as above "Get Time Stamp"
while (true)
{
    int A = d2fl;
    Thread.Sleep(5);
    int B = d2fl;
    if (A < B && d2fl < prox && speedGov > 2)
    {
        string hours = DateTime.Now.ToString("HH");
        string minutes = DateTime.Now.ToString("mm");
        string seconds = DateTime.Now.ToString("ss");
        string milliseconds = DateTime.Now.ToString("fff");
        lapFinishTimeStamp = (Convert.ToDecimal(hours) * 3600) +     (Convert.ToDecimal(minutes) * 60) + Convert.ToDecimal(seconds) + (Convert.ToDecimal(milliseconds) / 1000);
        A = 0;
        B = 0;
        break;
        }
    A = 0;
    B = 0;
}

Have read some other anwsers on this forum but are a few years old. This app will need to work on Galaxy S4 onwards.

Plus I'm a little confused about the GPS frequency's, from what I've read the GPS frequency operates at quite a high rate (hardware is around 1.6 GHz) but the phones operating systems seems to cull the data to a lower frequency, is this intentional?

解决方案

Don't confuse the the radio frequency value (1.1-1.6GHz) from how frequently you will get location updates (1Hz).

Have you seen the device list in: Get GPS position on a precise time interval ? Even though its a few years old, I doubt any on device GPS will report any faster (probably due to battery/noise/use case design). Even if the on board device was reporting at 10Hz or 20Hz that is only 100ms or 50ms which is still slower than your requirement of 25ms. Remember if the CPU is talking to the GPS and calculating location - it is eating battery which is the limiting factor on mobile devices.

If you want consistent sub-second GPS value updates you'll need to use an external device.

这篇关于Android GPS更新频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆