gpt4 book ai didi

windows-phone-7 - 如何在WP7上进行GPS查找时捕获错误

转载 作者:行者123 更新时间:2023-12-03 07:55:37 25 4
gpt4 key购买 nike

我试图在GPS不可用时提醒用户(基本上是在他们关闭地理位置服务的情况下)

以下是我的查询用例语句,我注意到在模拟器中我达到了“”状态,因此我无法在此处返回错误,因为它仍按预期运行

    void MyStatusChanged(GeoPositionStatusChangedEventArgs e)
{
switch (e.Status)
{
case GeoPositionStatus.Disabled:
client.ClientCallBackWithError("fail");
break;
case GeoPositionStatus.Initializing:
var y = "initializing location service,";
break;
case GeoPositionStatus.NoData:
// The location service is working, but it cannot get location data
// Alert the user and enable the Stop Location button
var z = "data unavailable,";
break;
case GeoPositionStatus.Ready:
var zzz = "receiving data, ";
break;

}
}

因此,在我的调用页面/ View 内部,我决定也许可以等待10秒钟,以查看是否被击中..否则,我可能会抛出错误/等

警告巨大的骇客,因为我失去了希望
    private void FindByGps_Click(object sender, RoutedEventArgs e)
{
gpsStarted = false;
gpsEnded = false;

progressHelper.StartProgressStuff(this.progress);
gpsStarted = true;
gpsLocationLookupService.StartLocationService();
this.Dispatcher.BeginInvoke(() => ListenForCallbackDuringGpsLookup(0));
}

private object ListenForCallbackDuringGpsLookup(int counter)
{
if (gpsStarted && !gpsEnded && counter < 12)
{
//keep looking until the timer runs out ...
counter = counter + 1;
this.Dispatcher.BeginInvoke(() => SleepForASec());
ListenForCallbackDuringGpsLookup(counter);
}
else if (gpsStarted && gpsEnded)
{
gpsStarted = false;
gpsEnded = false;
}else{
this.Dispatcher.BeginInvoke(() => SetCurrentLocationAndLaunchFindKiosks(null, "Failed to locate you by GPS"));
}

return null;
}

private object SleepForASec()
{
Thread.Sleep(1000);

return null;
}

但是第二次我启动了一个线程,它似乎锁定了应用程序,直到线程完成为止。

所以我的问题-我应该如何捕获此类gps错误信息以提供正确的反馈?

最佳答案

您看过这个API了吗?

http://msdn.microsoft.com/en-us/library/system.device.location.geocoordinatewatcher.trystart(v=VS.92).aspx

根据此处的说明,您应该可以在以下框架内进行操作:

public partial class MainPage : PhoneApplicationPage
{
GeoCoordinateWatcher watcher;

// Constructor
public MainPage()
{
InitializeComponent();
Loaded += (source, args) =>
{
watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);

watcher.PositionChanged += (sender, e) =>
{
// update the user
};

watcher.StatusChanged += (sender, e) =>
{
// update the user
};

if (!watcher.TryStart(false, TimeSpan.FromSeconds(5)))
{
// show the error somewhere
}
};
}
}

然后,在应用程序执行期间,如果GPS出现问题(信号丢失等),则可以在StatusChanged事件处理程序内进行适当响应。

让我知道我是否不满意,我将继续考虑更好的解决方案...

关于windows-phone-7 - 如何在WP7上进行GPS查找时捕获错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7251537/

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