// Distance measure
    public static float DistanceTo(XmlTimeline.Coordinates wp1, XmlTimeline.Coordinates wp2, char unit = 'K')
    {
        // Copied from
        // https://stackoverflow.com/questions/6366408/calculating-distance-between-two-latitude-and-longitude-geocoordinates


        double rlat1 = Math.PI * wp1.lat / 180;

        double rlat2  = Math.PI * wp2.lat / 180;
        double theta  = wp1.lon - wp2.lon;
        double rtheta = Math.PI * theta / 180;
        double dist   =
            Math.Sin(rlat1) * Math.Sin(rlat2) + Math.Cos(rlat1) *
            Math.Cos(rlat2) * Math.Cos(rtheta);

        dist = Math.Acos(dist);
        dist = dist * 180 / Math.PI;
        dist = dist * 60 * 1.1515;

        float distF = (float)dist;

        switch (unit)
        {
        case 'K':                 //Kilometers -> default
            return(distF * 1.609344f);

        case 'N':                 //Nautical Miles
            return(distF * 0.8684f);

        case 'M':                 //Miles
            return(distF);
        }

        return(distF);
    }
    void GetPlace(GpxTools.Gpx.GpxWayPoint waypoint)
    {
        // location
        XmlTimeline.Coordinates location = new XmlTimeline.Coordinates(waypoint.Latitude, waypoint.Longitude);
        // time
        DateTime?startTime = waypoint.Time;
        // ele
        double?ele = waypoint.Elevation;
        // name (if exist)
        string name = waypoint.Name;
        string link = "";

        if (waypoint.Links.Count > 0)
        {
            link = waypoint.Links[0].Href;
        }
        // If previous is place
        if (timelineItems.Count >= 1 && timelineItems.Last().type == XmlTimeline.TimelineItemType.place)
        {
            if (!timelineItems.Last().place.endTime.HasValue&& startTime.HasValue)
            {
                timelineItems.Last().place.endTime = startTime;
            }
            else
            {
                startTime = timelineItems.Last().place.startTime;
            }
        }
        else if (timelineItems.Count >= 1 && timelineItems.Last().type == XmlTimeline.TimelineItemType.activity && !startTime.HasValue)
        {
            startTime = timelineItems.Last().activity.endTime;
        }
        timelineItems.Add(new XmlTimeline.TimelineItem(new XmlTimeline.Place(location, name, startTime, ele, link)));
    }
 public static float DistanceTo(JsonMoves.Day.Segment.Place.Location jwp1, JsonMoves.Day.Segment.Place.Location jwp2, char unit = 'K')
 {
     XmlTimeline.Coordinates wp1 = new XmlTimeline.Coordinates(jwp1.lat, jwp1.lon);
     XmlTimeline.Coordinates wp2 = new XmlTimeline.Coordinates(jwp2.lat, jwp2.lon);
     return(DistanceTo(wp1, wp2, unit));
 }