public static double ProjectedLength(this LapViewModel lap)
        {
            var geographicLapDataPoints = lap.DataPoints.Where(dp => dp.Latitude.HasValue && dp.Longitude.HasValue);

            if (!geographicLapDataPoints.Any())
            {
                return(0d);
            }

            GeographyPoint firstGeographyPoint = null;
            GeographyPoint lastGeographyPoint  = null;
            double         length = geographicLapDataPoints.Aggregate(Tuple.Create(0d, (GeographyPoint)null), (a, b) =>
            {
                var currentGeoPoint = b.AsGeographyPoint();
                if (firstGeographyPoint == null)
                {
                    firstGeographyPoint = currentGeoPoint;
                }
                lastGeographyPoint = currentGeoPoint;
                double distance    = a.Item2 == null || (a.Item2.Latitude == currentGeoPoint.Latitude && a.Item2.Longitude == currentGeoPoint.Longitude)
                                                        ? a.Item1
                                                        : a.Item1 + a.Item2.Distance(currentGeoPoint);
                return(Tuple.Create(distance, currentGeoPoint));
            }, a => a.Item1);

            // Add distance between last and first points to complete circuit
            if (lastGeographyPoint != null)
            {
                length += lastGeographyPoint.Distance(firstGeographyPoint);
            }

            return(length);
        }
 public static double GetDistance(GeographyPoint point1, GeographyPoint point2)
 {
     if (point1 == null)
     {
         throw new ArgumentNullException("point1");
     }
     if (point2 == null)
     {
         throw new ArgumentNullException("point2");
     }
     return(point1.Distance(point2).Value);
 }