private void MapLocation(double latitude, double longitude)
{
if (Math.Round(lastLat, 5) == Math.Round(latitude) && Math.Round(lastLon, 5) == Math.Round(longitude, 5))
{
// hasn't moved far enough yet...
return;
}
lastLat = latitude;
lastLon = longitude;
bool first = false;
if (currentFlight == null)
{
first = true;
currentFlight = new MapPolyline();
currentFlight.StrokeThickness = 4;
currentFlight.Stroke = new SolidColorBrush(Colors.Magenta);
currentFlight.Locations = new LocationCollection();
myMap.Children.Add(currentFlight);
}
currentFlight.Locations.Add(new Location() { Latitude = latitude, Longitude = longitude });
// make sure it's on top.
if (myMap.Children.IndexOf(currentFlight) < 0)
{
myMap.Children.Add(currentFlight);
}
else if (myMap.Children.IndexOf(currentFlight) != myMap.Children.Count - 1)
{
myMap.Children.Remove(currentFlight);
myMap.Children.Add(currentFlight);
}
if (currentFlight.Locations.Count > 1000)
{
// remove the older points.
currentFlight.Locations.RemoveAt(0);
}
if (first && myMap.Visibility == Visibility.Visible)
{
myMap.SetView(currentFlight.Locations, new Thickness(20.0), 0);
}
}