private void AddWaypointMarkerToMap(TimedPosition waypoint)
 {
     WaypointMarker actualMarker = new WaypointMarker(this, String.Format("Lat  : {0}\nLong : {1}", waypoint.Position.X, waypoint.Position.Y));
     MapMarker mm = MapControl.AddMarker(actualMarker, waypoint.Position.X, waypoint.Position.Y);
     waypoint.MapMarker = mm;
 }
        private void btnUpdatePoint_Click(object sender, RoutedEventArgs e)
        {
            int index = lvRoute.SelectedIndex;
            if (index == -1) return;

            double lat, lng;
            TimeSpan time;
            if (!Double.TryParse(tbPositionLat.Text, out lat) || !Double.TryParse(tbPositionLng.Text, out lng)) return;
            if (!TimeSpan.TryParse(tbTime.Text, out time)) return;

            TimedPosition waypoint = new TimedPosition(time, lat, lng);
            WaypointMarker newMarker = new WaypointMarker(this, String.Format("Lat  : {0}\nLong : {1}", waypoint.Position.X, waypoint.Position.Y));
            MapMarker mm = MapControl.ReplaceMarker(route[index].MapMarker, newMarker, waypoint.Position.X, waypoint.Position.Y);
            waypoint.MapMarker = mm;
            route[index] = waypoint;

            lvRoute.SelectedIndex = index;
            MapControl.RegenerateRouteShape();
            return;

        }
 private bool AddWaypointAtCurrentPosition()
  {
      double lat, lng;
      TimeSpan time;
      if (!Double.TryParse(tbPositionLat.Text, out lat) || !Double.TryParse(tbPositionLng.Text, out lng)) return false;
      if (!TimeSpan.TryParse(tbTime.Text, out time)) return false;
      // Find the right location to insert the new stop at
      int i = 0;
      for (; i < route.Count; i++)
      {
          if (route[i].Time > time) break;
          if (route[i].Time == time)
          {
              MessageBox.Show(String.Format("Can't be in two places at the same time.\nThere's already a waypoint at time {0}.\nPlease select a different time for the new waypoint.", time), MSG_BOX_CAPTION, MessageBoxButton.OK, MessageBoxImage.Exclamation);
              return false;
          }
      }
      TimedPosition waypoint = new TimedPosition(time, lat, lng);
      route.Insert(i, waypoint);
      AddWaypointMarkerToMap(waypoint);
      MapControl.RegenerateRouteShape();
      return true;
  }