【问题标题】:GetGeopositionAsync takes too long to completeGetGeopositionAsync 完成时间过长
【发布时间】:2014-06-29 06:19:55
【问题描述】:

当前我使用此代码获取 GPS:

Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracy = PositionAccuracy.Default;
geolocator.DesiredAccuracyInMeters = 50;
try
{
    Geoposition currentPosition = await geolocator.GetGeopositionAsync(TimeSpan.FromSeconds(120), TimeSpan.FromSeconds(30));
    MyCoordinate = new GeoCoordinate(currentPosition.Coordinate.Latitude, currentPosition.Coordinate.Longitude);
}
catch (Exception ex)
{
    if (ex.Message.Contains("This operation returned because the timeout period expired."))
    {
        MessageBox.Show("GPS is taking too long too complete. Pleaes try again.");
        this.SetProgressIndicator(false);
        RadBusyIndicator.IsRunning = false;
        return;
    }
    else
    {                           
        this.SetProgressIndicator(false);
        RadBusyIndicator.IsRunning = false;
        return;
    }
};

但它总是需要很长时间才能完成,如您所见,我将超时设置为 30 秒但不知道为什么 超过 30 秒时不显示超时异常。 我被困在这个问题上。有人知道吗?

【问题讨论】:

  • 正在发生什么
  • @RowlandShaw 一百台设备正在使用我的应用程序和这些获取 GPS 的代码,但其中 10% 的设备警告我,尽管我设置了超时时间(30 秒),但获取 GPS 需要很长时间。谢谢

标签: c# windows-phone-8 gps geolocation location


【解决方案1】:

确保 wifi 或手机设备已开启,这样可以在 GPS 设备找不到信号时使用备用方法。

有或多或少相同问题的人在这里发了另一个帖子:
GetGeopositionAsync does not return

有关 GeoLocator 类的更多信息: http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geolocator#properties

【讨论】:

    【解决方案2】:

    我也不知道为什么,但是 TimeSpan 确实很慢,但是使用 ReportInterval 可以正常工作:

    geolocator = new Geolocator();
    geolocator.DesiredAccuracy = PositionAccuracy.High;
    geolocator.ReportInterval = 2000;
    geolocator.PositionChanged += geolocator_PositionChanged;
    
    private void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
    {
    try
    {
        Dispatcher.BeginInvoke(() =>
        {
            myPosition = args.Position.Coordinate.ToGeoCoordinate();
        });
    }
    catch(Exception ex)
    {
        if (ex.Data == null) throw;
        else MessageBox.Show("Exception while Tracking: " + ex.InnerException.ToString());
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-24
      • 2023-03-16
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-03
      相关资源
      最近更新 更多