示例#1
0
        //Get Offset needs current location to know whether to apply 30W rule
        public static Location CalculateHashLocation(Location currentLocation, Location offset)
        {
            var lat = currentLocation.Latitude > 0 ? Math.Floor(currentLocation.Latitude) + offset.Latitude : Math.Ceiling(currentLocation.Latitude) - offset.Latitude;
            var lon = currentLocation.Longitude > 0 ? Math.Floor(currentLocation.Longitude) + offset.Longitude : Math.Ceiling(currentLocation.Longitude) - offset.Longitude;

            var loc = new Location(lat, lon);

            return(loc);
        }
示例#2
0
        private static Location CalculateGlobalHash(Location offset)
        {
            var latDecimalPart = offset.Latitude;
            var lonDecimalPart = offset.Longitude;

            var globalLat = latDecimalPart * 180 - 90;
            var globalLon = lonDecimalPart * 360 - 180;

            var loc = new Location(globalLat, globalLon);

            return(loc);
        }
示例#3
0
        /// <summary>
        /// If a location is east of 30w, returns previous date. Otherwise returns same date
        /// </summary>
        /// <param name="date"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        public static DateTime Get30WCompliantDate(DateTime date, Location location)
        {
            //Check 30W rule
            var djDate = date;

            if (location.Longitude >= -30)
            {
                djDate = date.AddDays(-1);
                Debug.WriteLine($"Using 30W rule. Selected date: {date} DJDate: {djDate}");
            }
            else
            {
                Debug.WriteLine($"Not using 30W rule. Selected date: {date} DJDate: {djDate}");
            }
            return(djDate);
        }
        //This bearing is relative to true north and doesn't use declination
        //Thanks to http://www.movable-type.co.uk/scripts/latlong.html
        public double GetBearingRelativeToTrueNorth(Location currentLocation, Location destination)
        {
            var lat1 = currentLocation.Latitude.ToRadians();
            var lon1 = currentLocation.Longitude.ToRadians();
            var lat2 = destination.Latitude.ToRadians();
            var lon2 = destination.Longitude.ToRadians();

            var dlon = lon2 - lon1;

            var y = Math.Sin(dlon) * Math.Cos(lat2);
            var x = (Math.Cos(lat1) * Math.Sin(lat2)) - (Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(dlon));

            var bearing          = Math.Atan2(y, x);
            var bearingInDegrees = bearing.ToDegrees();

            var normalisedBearing = (bearingInDegrees + 360) % 360;

            return(normalisedBearing);
        }
示例#5
0
        public static async Task <Response <HashLocation> > GetHashData(DateTime date, Location currentLocation)
        {
            var date30W = DowJonesDates.Get30WCompliantDate(date, currentLocation);
            var djDate  = DowJonesDates.GetApplicableDJDate(date30W);
            var djia    = await Webclient.GetDjia(djDate);

            if (!djia.Success)
            {
                return(new Response <HashLocation>(null, false, djia.Message));
            }
            var offset = CalculateOffset(date, djia.Data);
            var loc    = CalculateHashLocation(currentLocation, offset);

            var hash = new HashLocation(loc.Latitude, loc.Longitude, date, false, false);

            return(new Response <HashLocation>(hash, true, "Hashes calculated successfully"));
        }
        public double CalculateDistance(Location start, Location end)
        {
            var distance = Xamarin.Essentials.Location.CalculateDistance(start.ToEssentialsLocation(), end.ToEssentialsLocation(), DistanceUnits.Kilometers);

            return(distance);
        }