示例#1
0
        public List<Event> relatedEvents(GeoLocation location)
        {
            List<Event> relatedEvents = new List<Event>();
            foreach (Event e in _db.Events)
            {
                double distanceInKm = e.DistanceBetweenPlaces(location);
                if (e.isRelevantTimeEvent()) // time of Event is relevant
                {
                    if (distanceInKm <= e.LocationRadius)
                    {
                        relatedEvents.Add(e);
                    }
                }

            }
            return relatedEvents;
        }
示例#2
0
        public double DistanceBetweenPlaces(GeoLocation e2)
        {
            double R = 6371; // km

            double sLat1 = Math.Sin(Radians(this.LocationLatitude));
            double sLat2 = Math.Sin(Radians(e2.LocationLatitude));
            double cLat1 = Math.Cos(Radians(this.LocationLatitude));
            double cLat2 = Math.Cos(Radians(e2.LocationLatitude));
            double cLon = Math.Cos(Radians(this.LocationLongitude) - Radians(e2.LocationLongitude));

            double cosD = sLat1 * sLat2 + cLat1 * cLat2 * cLon;

            double d = Math.Acos(cosD);

            double dist = R * d;

            return dist;
        }
示例#3
0
        public GeoLocation MiddlePointBetweenPlaces(GeoLocation e2)
        {
            double dLon = Radians(e2.LocationLongitude - this.LocationLongitude);

            //convert to radians
            double lat1 = Radians(this.LocationLatitude);
            double lat2 = Radians(e2.LocationLatitude);
            double lon1 = Radians(this.LocationLongitude);

            double Bx = Math.Cos(lat2) * Math.Cos(dLon);
            double By = Math.Cos(lat2) * Math.Sin(dLon);
            double latMid = Math.Atan2(Math.Sin(lat1) + Math.Sin(lat2), Math.Sqrt((Math.Cos(lat1) + Bx) * (Math.Cos(lat1) + Bx) + By * By));
            double lonMid = lon1 + Math.Atan2(By, Math.Cos(lat1) + Bx);

            return new GeoLocation(RadianToDegree(lonMid), RadianToDegree(latMid));
        }