因此,我正在使用本指南,但在测试以确定它是否有效时运气为零。该代码的唯一变化是,我没有更改 TextBlock,而是设置了一个在函数外部声明的静态 GeoCoordinate 对象。
public static void PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
coord = e.Position.Location;
}
好吧,我将状态更改为显示一个带有 OK 按钮的 MessageBox,而不是显示在文本框中,并删除了按钮事件。
在 MainPage 渲染中,我有:
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if (watcher == null)
{
watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
watcher.MovementThreshold = 20;
watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(StatusChanged);
watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(PositionChanged);
}
watcher.Start();
if (!App.ViewModel.IsDataLoaded)
{
string blah = "";
blah += coord.Latitude.ToString();
blah += "; " + coord.Longitude.ToString();
但是,如果我不初始化坐标,它会出错(可以理解)但是如果我这样做 = new GeoCoordinate(); 它为所有数字项返回 NaN。我在从未命中的事件处理程序中设置了断点(虽然是预期的行为?)
在模拟器中,我使用了 >> 的东西,将其设置为 live 并选择了几个位置,将切换位置的时间设置为 10 秒并在运行调试时播放它。我是否在错误地调试/运行模拟器的位置部分?
更新:在更新它以删除字符串 blah items 以根据位置创建列表后,它似乎正在工作。