Windows Phone - 重复获取纬度和经度

时间:2012-07-20 12:27:42

标签: c# gps windows-phone

我正在尝试编写一个允许用户跟踪其位置的Windows Phone应用。我希望他们能够点击按钮并获取他们当前的位置。我当前的方法适用于记录的第一个位置。但是,当我尝试获取后续位置时,纬度/经度与原始位置相同。我目前正在使用以下内容:

private static GeoCoordinateWatcher coordinateWatcher = null;
private void myButton_Click(object sender, EventArgs e)
{
  coordinateWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
  coordinateWatcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(coordinateWatcher_StatusChanged);
  coordinateWatcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(coordinateWatcher_PositionChanged);
  coordinateWatcher.Start();
}


private void coordinateWatcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
  GeoPositionStatus status = e.Status;
  if (status == GeoPositionStatus.Disabled)
  {
    coordinateWatcher.Stop();           // Preserve the battery life
    coordinateWatcher = null;
  }
  else if (status == GeoPositionStatus.Ready)
  {
    /* Do Nothing */
  }
  else if (status == GeoPositionStatus.NoData)
  {
    coordinateWatcher.Stop();           // Preserve the battery life
    coordinateWatcher = null;
  }
}

private void coordinateWatcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
  GeoCoordinate coordinates = e.Position.Location;
  MessageBox.Show("You're at " + coordinates.Latitude + ", " + coordinates.Longitude);

  coordinateWatcher.Stop();       // Save the battery
  coordinateWatcher = null;
}

为什么后续坐标与原始坐标相同?我做错了什么?

0 个答案:

没有答案