Beispiel #1
0
        /// <summary>
        /// Calculate the intersection point of two line segments
        /// adapted to C# from http://rbrundritt.wordpress.com/2008/10/20/approximate-points-of-intersection-of-two-line-segments/
        /// </summary>
        /// <returns>Null if there is no intersection. Otherwise the point of intersection.</returns>
        public static IGeoLocation SimplePolylineIntersection(IGeoLocation latlong1, IGeoLocation latlong2, IGeoLocation latlong3, IGeoLocation latlong4)
        {
            //Line segment 1 (p1, p2)
            var a1 = latlong2.Latitude - latlong1.Latitude;
            var b1 = latlong1.Longitude - latlong2.Longitude;
            var c1 = a1 * latlong1.Longitude + b1 * latlong1.Latitude;

            //Line segment 2 (p3,  p4)
            var a2 = latlong4.Latitude - latlong3.Latitude;
            var b2 = latlong3.Longitude - latlong4.Longitude;
            var c2 = a2 * latlong3.Longitude + b2 * latlong3.Latitude;

            var determinate = a1 * b2 - a2 * b1;

            IGeoLocation intersection;
            if (determinate != 0)
            {
                var x = (b2 * c1 - b1 * c2) / determinate;
                var y = (a1 * c2 - a2 * c1) / determinate;

                var intersect = new GeoLocation(y, x);

                if (InBoundedBox(latlong1, latlong2, intersect) && InBoundedBox(latlong3, latlong4, intersect))
                    intersection = intersect;
                else
                    intersection = null;
            }
            else //lines are parallel
                intersection = null;

            return intersection;
        }
        public LocationViewModel()
        {
            geo = DependencyService.Get<IGeoLocation>();
            pos = new Position(39.8282, -98.5795);
            address = "Waiting for GPS signal...";
            displayLoc = "Waiting for GPS signal...";

            isBusy = false;
            intLocCount = 0;

            MessagingCenter.Subscribe<IGeoLocation, Position>(this, "LocationChanged", (sender, arg) =>
            {
                this.LocationChanged((Position)arg);
            });
        }
Beispiel #3
0
        private static async Task ActionsWhenTravelToSnipeTarget(ISession session, CancellationToken cancellationToken,
                                                                 IGeoLocation pokemon, bool allowCatchPokemon, bool allowSpinPokeStop)
        {
            var distance = LocationUtils.CalculateDistanceInMeters(
                pokemon.Latitude,
                pokemon.Longitude,
                session.Client.CurrentLatitude,
                session.Client.CurrentLongitude
                );

            if (allowCatchPokemon && distance > 50.0)
            {
                // Catch normal map Pokemon
                await CatchNearbyPokemonsTask.Execute(session, cancellationToken, sessionAllowTransfer : false).ConfigureAwait(false);
            }
            if (allowSpinPokeStop)
            {
                //looking for neaby pokestop. spin it
                await UseNearbyPokestopsTask.SpinPokestopNearBy(session, cancellationToken, null).ConfigureAwait(false);
            }
        }
Beispiel #4
0
        public override async Task <PlayerUpdateResponse> Walk(IGeoLocation targetLocation, Func <Task> functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken, double walkSpeed = 0.0)
        {
            GetGoogleInstance(session);

            _minStepLengthInMeters = session.LogicSettings.DefaultStepLength;
            var currentLocation      = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude, _client.CurrentAltitude);
            var destinaionCoordinate = new GeoCoordinate(targetLocation.Latitude, targetLocation.Longitude);

            var googleWalk = _googleDirectionsService.GetDirections(currentLocation, new List <GeoCoordinate>(), destinaionCoordinate);

            if (googleWalk == null)
            {
                return(await RedirectToNextFallbackStrategy(session.LogicSettings, targetLocation, functionExecutedWhileWalking, session, cancellationToken, walkSpeed));
            }

            base.OnStartWalking(session, targetLocation, googleWalk.Distance);

            List <GeoCoordinate> points = googleWalk.Waypoints;

            return(await DoWalk(points, session, functionExecutedWhileWalking, currentLocation, destinaionCoordinate, cancellationToken, walkSpeed));
        }
        public override async Task Walk(IGeoLocation targetLocation,
                                        Func <Task> functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken,
                                        double walkSpeed = 0.0)
        {
            GetYoursInstance(session);
            var destinaionCoordinate = new GeoCoordinate(targetLocation.Latitude, targetLocation.Longitude);
            var sourceLocation       = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude, _client.CurrentAltitude);
            var yoursWalk            = _yoursDirectionsService.GetDirections(sourceLocation, destinaionCoordinate);

            if (yoursWalk == null)
            {
                await RedirectToNextFallbackStrategy(session.LogicSettings, targetLocation, functionExecutedWhileWalking, session, cancellationToken).ConfigureAwait(false);

                return;
            }

            base.OnStartWalking(session, targetLocation, yoursWalk.Distance);
            List <GeoCoordinate> points = yoursWalk.Waypoints;

            await DoWalk(points, session, functionExecutedWhileWalking, sourceLocation, destinaionCoordinate, cancellationToken, walkSpeed).ConfigureAwait(false);
        }
Beispiel #6
0
        public async Task Move(IGeoLocation targetLocation,
                               Func <Task> functionExecutedWhileWalking,
                               ISession session,
                               CancellationToken cancellationToken, double customWalkingSpeed = 0.0)
        {
            _AutoWalkAI   = session.LogicSettings.AutoWalkAI;
            _AutoWalkDist = session.LogicSettings.AutoWalkDist;

            distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude, session.Client.CurrentLongitude,
                                                               targetLocation.Latitude, targetLocation.Longitude);

            cancellationToken.ThrowIfCancellationRequested();
            TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();

            // If the stretegies become bigger, create a factory for easy management

            //Logging.Logger.Write($"Navigation - Walking speed {customWalkingSpeed}");
            InitializeWalkStrategies(session.LogicSettings);
            WalkStrategy = GetStrategy(session.LogicSettings);
            await WalkStrategy.Walk(targetLocation, functionExecutedWhileWalking, session, cancellationToken, customWalkingSpeed).ConfigureAwait(false);
        }
Beispiel #7
0
        /// <summary>
        /// Check if the calculated point is within the bounding box
        /// </summary>
        /// <param name="latlong1">The first coordinate which makes up the bounded box</param>
        /// <param name="latlong2">The second coordinate which makes up the bounded box</param>
        /// <param name="latlong3">a point that we are checking to see is inside the box</param>
        /// <returns></returns>
        private static bool InBoundedBox(IGeoLocation latlong1, IGeoLocation latlong2, IGeoLocation latlong3)
        {
            bool betweenLats;
            bool betweenLons;

            if (latlong1.Latitude < latlong2.Latitude)
                betweenLats = (latlong1.Latitude <= latlong3.Latitude &&
                               latlong2.Latitude >= latlong3.Latitude);
            else
                betweenLats = (latlong1.Latitude >= latlong3.Latitude &&
                               latlong2.Latitude <= latlong3.Latitude);

            if (latlong1.Longitude < latlong2.Longitude)
                betweenLons = (latlong1.Longitude <= latlong3.Longitude &&
                               latlong2.Longitude >= latlong3.Longitude);
            else
                betweenLons = (latlong1.Longitude >= latlong3.Longitude &&
                               latlong2.Longitude <= latlong3.Longitude);

            return (betweenLats && betweenLons);
        }
Beispiel #8
0
        public void OnStartWalking(ISession session, IGeoLocation desination, double calculatedDistance = 0.0)
        {
            var distance = calculatedDistance;

            if (distance == 0)
            {
                distance = this.CalculateDistance(session.Client.CurrentLatitude, session.Client.CurrentLongitude,
                                                  desination.Latitude, desination.Longitude);
            }

            if (desination is FortLocation)
            {
                var fortLocation = desination as FortLocation;
                session.EventDispatcher.Send(new FortTargetEvent
                {
                    Name     = desination.Name,
                    Distance = distance,
                    Route    = this.RouteName,
                    Type     = fortLocation.FortData.Type
                });
            }
        }
Beispiel #9
0
        /// <summary>
        /// Calculates aerial distance between the two geo locations.
        /// </summary>
        public static double AerialDistance(IGeoLocation point1, IGeoLocation point2)
        {
            if (point1 == null || point2 == null)
            {
                return(0.0);
            }

            var R = 6371E3; // meters

            var lat1 = DegreesToRadians(point1.Latitude);
            var lon1 = DegreesToRadians(point1.Longitude);
            var lat2 = DegreesToRadians(point2.Latitude);
            var lon2 = DegreesToRadians(point2.Longitude);

            var dlat = lat2 - lat1;
            var dlon = lon2 - lon1;

            var a = Sin(dlat / 2) * Sin(dlat / 2) + Cos(lat1) * Cos(lat2) * Sin(dlon / 2) * Sin(dlon / 2);
            var c = 2 * Atan2(Sqrt(a), Sqrt(1 - a));

            return(c * R);
        }
Beispiel #10
0
 public abstract Task <PlayerUpdateResponse> Walk(IGeoLocation targetLocation, Func <Task> functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken, double walkSpeed = 0.0);
Beispiel #11
0
        public static string ToGoogleMapsLink(this IGeoLocation location)
        {
            var formatter = new GoogleMapsLinkFormatter();

            return(location.ToFormattedString(formatter));
        }
        /// <summary>
        /// Finds the specified location.
        /// </summary>
        /// <param name="location">The location.</param>
        /// <returns>Task&lt;IList&lt;IAddress&gt;&gt;.</returns>
        public async Task <IGeoSearchResult> FindAsync(IGeoLocation location)
        {
            var result = await _wrapper.FindLocationAsync(location).ConfigureAwait(false);

            return(result);
        }
Beispiel #13
0
 ///<summary>
 ///  A constructor that takes a <seealso cref = "GeoLocation" /> as a parameter.
 ///</summary>
 ///<param name = "location">
 ///  the location </param>
 public ZmanimCalendar(IGeoLocation location)
     : base(location)
 {
 }
Beispiel #14
0
        /// <summary>
        /// Calculate the bearing from a to b
        /// </summary>
        /// <param name="a">Location a</param>
        /// <param name="b">Location b</param>
        /// <returns>degrees</returns>
        public static double Bearing(IGeoLocation a, IGeoLocation b)
        {
            var y = Math.Sin(b.Longitude - a.Longitude) * Math.Cos(b.Latitude);
            var x = Math.Cos(a.Latitude) * Math.Sin(b.Latitude) -
                    Math.Sin(a.Latitude) * Math.Cos(b.Latitude) * Math.Cos(b.Longitude - a.Longitude);

            var brng = Math.Atan2(y, x) * 180 / Math.PI;
            return brng;
        }
Beispiel #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComplexZmanimCalendar"/> class.
 /// </summary>
 /// <param name="date">The date.</param>
 /// <param name="location">The location.</param>
 public ComplexZmanimCalendar(DateTime date, IGeoLocation location)
     : base(date, location)
 {
 }
 ///<summary>
 ///  A constructor that takes in as a parameter geolocation information
 ///</summary>
 ///<param name="dateTime">The DateTime</param>
 ///<param name = "geoLocation">
 ///  The location information used for astronomical calculating sun
 ///  times. </param>
 public AstronomicalCalendar(DateTime dateTime, IGeoLocation geoLocation)
     : this(new DateWithLocation(dateTime, geoLocation))
 {
 }
Beispiel #17
0
 /// <summary>
 /// Calculates the distance from this instance to destination location (in meters).
 /// </summary>
 /// <param name="src">The <see cref="IGeoLocation"/> to apply the method to.</param>
 /// <param name="dst">The destination location.</param>
 /// <param name="radiusofearthinmeters">The radius of the earth in meters (default: 6371000).</param>
 /// <returns>Returns the distance, in meters, from this instance to destination.</returns>
 /// <remarks>
 /// Note that we use the <a href="http://en.wikipedia.org/wiki/International_System_of_Units">International
 /// System of Units (SI)</a>; units of distance are specified in meters. If you want to use imperial system (e.g.
 /// miles, nautical miles, yards, foot and other units) you need to convert from/to meters. You can use the
 /// helper methods <see cref="GeoUtil.MilesToMeters"/> / <see cref="GeoUtil.MetersToMiles"/> and
 /// <see cref="GeoUtil.YardsToMeters"/> / <see cref="GeoUtil.MetersToYards"/> for quick conversion.
 /// </remarks>
 /// <seealso cref="GeoUtil.MilesToMeters"/>
 /// <seealso cref="GeoUtil.MetersToMiles"/>
 /// <seealso cref="GeoUtil.YardsToMeters"/>
 /// <seealso cref="GeoUtil.MetersToYards"/>
 public static double DistanceTo(this IGeoLocation src, IGeoLocation dst, double radiusofearthinmeters)
 {
     return(GeoUtil.DistanceTo(src, dst, radiusofearthinmeters));
 }
Beispiel #18
0
 /// <summary>
 /// Calculates the distance from the this instance to destination location (in meters).
 /// </summary>
 /// <param name="src">The <see cref="IGeoLocation"/> to apply the method to.</param>
 /// <param name="dst">The destination location.</param>
 /// <returns>Returns the distance, in meters, from this instance to destination.</returns>
 /// <remarks>
 /// Note that we use the <a href="http://en.wikipedia.org/wiki/International_System_of_Units">International
 /// System of Units (SI)</a>; units of distance are specified in meters. If you want to use imperial system (e.g.
 /// miles, nautical miles, yards, foot and other units) you need to convert from/to meters. You can use the
 /// helper methods <see cref="GeoUtil.MilesToMeters"/> / <see cref="GeoUtil.MetersToMiles"/> and
 /// <see cref="GeoUtil.YardsToMeters"/> / <see cref="GeoUtil.MetersToYards"/> for quick conversion.
 /// </remarks>
 /// <seealso cref="GeoUtil.MilesToMeters"/>
 /// <seealso cref="GeoUtil.MetersToMiles"/>
 /// <seealso cref="GeoUtil.YardsToMeters"/>
 /// <seealso cref="GeoUtil.MetersToYards"/>
 public static double DistanceTo(this IGeoLocation src, IGeoLocation dst)
 {
     return(GeoUtil.DistanceTo(src, dst));
 }
Beispiel #19
0
 /// <summary>
 /// Calculates the distance from this instance to destination location (in meters).
 /// </summary>
 /// <param name="loc">The <see cref="IGeoLocation"/> to apply the method to.</param>
 /// <param name="lat">The latitude of the destination point.</param>
 /// <param name="lng">The longitude of the destination point.</param>
 /// <param name="radiusofearthinmeters">The radius of the earth in meters (default: 6371000).</param>
 /// <returns>Returns the distance, in meters, from this instance to destination.</returns>
 /// <remarks>
 /// Note that we use the <a href="http://en.wikipedia.org/wiki/International_System_of_Units">International
 /// System of Units (SI)</a>; units of distance are specified in meters. If you want to use imperial system (e.g.
 /// miles, nautical miles, yards, foot and other units) you need to convert from/to meters. You can use the
 /// helper methods <see cref="GeoUtil.MilesToMeters"/> / <see cref="GeoUtil.MetersToMiles"/> and
 /// <see cref="GeoUtil.YardsToMeters"/> / <see cref="GeoUtil.MetersToYards"/> for quick conversion.
 /// </remarks>
 /// <seealso cref="GeoUtil.MilesToMeters"/>
 /// <seealso cref="GeoUtil.MetersToMiles"/>
 /// <seealso cref="GeoUtil.YardsToMeters"/>
 /// <seealso cref="GeoUtil.MetersToYards"/>
 public static double DistanceTo(this IGeoLocation loc, double lat, double lng, double radiusofearthinmeters)
 {
     return(GeoUtil.DistanceTo(loc, new GeoName {
         Latitude = lat, Longitude = lng
     }, radiusofearthinmeters));
 }
Beispiel #20
0
 /// <summary>
 /// Calculates the distance from this instance to destination location (in meters).
 /// </summary>
 /// <param name="loc">The <see cref="IGeoLocation"/> to apply the method to.</param>
 /// <param name="lat">The latitude of the destination point.</param>
 /// <param name="lng">The longitude of the destination point.</param>
 /// <returns>Returns the distance, in meters, from this instance to destination.</returns>
 /// <remarks>
 /// Note that we use the <a href="http://en.wikipedia.org/wiki/International_System_of_Units">International
 /// System of Units (SI)</a>; units of distance are specified in meters. If you want to use imperial system (e.g.
 /// miles, nautical miles, yards, foot and other units) you need to convert from/to meters. You can use the
 /// helper methods <see cref="GeoUtil.MilesToMeters"/> / <see cref="GeoUtil.MetersToMiles"/> and
 /// <see cref="GeoUtil.YardsToMeters"/> / <see cref="GeoUtil.MetersToYards"/> for quick conversion.
 /// </remarks>
 /// <seealso cref="GeoUtil.MilesToMeters"/>
 /// <seealso cref="GeoUtil.MetersToMiles"/>
 /// <seealso cref="GeoUtil.YardsToMeters"/>
 /// <seealso cref="GeoUtil.MetersToYards"/>
 public static double DistanceTo(this IGeoLocation loc, double lat, double lng)
 {
     return(GeoUtil.DistanceTo(loc, new GeoName {
         Latitude = lat, Longitude = lng
     }));
 }
Beispiel #21
0
 public static double Distance(IGeoLocation city1, IGeoLocation city2)
 {
     return GeoLocationTools.VincentyDistanceFormula(city1, city2);
 }
Beispiel #22
0
 /// <summary>
 /// Calculates a coordinate from a GeoName (latitude, longitude, altitude)
 /// </summary>
 /// <param name="n">The GeoName to determine the coordinate for.</param>
 /// <param name="radiusofearth">Radius of the earth, in meters.</param>
 /// <returns>Returns a coordinate (represented as an array of 3 doubles).</returns>
 /// <remarks>This method is for internal use (for the KdTree) only.</remarks>
 internal static double[] GetCoord(IGeoLocation n, double radiusofearth = RADIUSOFEARTH)
 {
     return new[] {
         radiusofearth * Math.Cos(GeoUtil.Deg2Rad(n.Latitude)) * Math.Cos(GeoUtil.Deg2Rad(n.Longitude)),
         radiusofearth * Math.Cos(GeoUtil.Deg2Rad(n.Latitude)) * Math.Sin(GeoUtil.Deg2Rad(n.Longitude)),
         radiusofearth * Math.Sin(GeoUtil.Deg2Rad(n.Latitude))
     };
 }
        public override async Task <PlayerUpdateResponse> Walk(IGeoLocation targetLocation,
                                                               Func <Task> functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken,
                                                               double walkSpeed = 0.0)
        {
            cancellationToken.ThrowIfCancellationRequested();
            TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
            var destinaionCoordinate = new GeoCoordinate(targetLocation.Latitude, targetLocation.Longitude);

            //PlayerUpdateResponse result = null;

            if (CurrentWalkingSpeed <= 0)
            {
                CurrentWalkingSpeed = session.LogicSettings.WalkingSpeedInKilometerPerHour;
            }
            if (session.LogicSettings.UseWalkingSpeedVariant && walkSpeed == 0)
            {
                CurrentWalkingSpeed = session.Navigation.VariantRandom(session, CurrentWalkingSpeed);
            }

            var rw = new Random();
            var speedInMetersPerSecond = (walkSpeed > 0 ? walkSpeed : CurrentWalkingSpeed) / 3.6;
            var sourceLocation         = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);

            LocationUtils.CalculateDistanceInMeters(sourceLocation, destinaionCoordinate);
            var nextWaypointBearing    = LocationUtils.DegreeBearing(sourceLocation, destinaionCoordinate);
            var nextWaypointDistance   = speedInMetersPerSecond;
            var waypoint               = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);
            var requestSendDateTime    = DateTime.Now;
            var requestVariantDateTime = DateTime.Now;

            var result = await LocationUtils
                         .UpdatePlayerLocationWithAltitude(session, waypoint, (float)speedInMetersPerSecond);

            double SpeedVariantSec = rw.Next(1000, 10000);

            base.DoUpdatePositionEvent(session, waypoint.Latitude, waypoint.Longitude, walkSpeed, CurrentWalkingSpeed);

            do
            {
                cancellationToken.ThrowIfCancellationRequested();
                TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;
                var millisecondsUntilVariant =
                    (DateTime.Now - requestVariantDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils
                                              .CalculateDistanceInMeters(sourceLocation, destinaionCoordinate);

                //if (currentDistanceToTarget < 40)
                //{
                //    if (speedInMetersPerSecond > SpeedDownTo)
                //    {
                //        //Logger.Write("We are within 40 meters of the target. Speeding down to 10 km/h to not pass the target.", LogLevel.Info);
                //        speedInMetersPerSecond = SpeedDownTo;
                //    }
                //}

                if (session.LogicSettings.UseWalkingSpeedVariant && walkSpeed == 0)
                {
                    CurrentWalkingSpeed    = session.Navigation.VariantRandom(session, CurrentWalkingSpeed);
                    speedInMetersPerSecond = CurrentWalkingSpeed / 3.6;
                }

                nextWaypointDistance = Math.Min(currentDistanceToTarget,
                                                millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, destinaionCoordinate);
                waypoint            = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                result = await LocationUtils
                         .UpdatePlayerLocationWithAltitude(session, waypoint, (float)speedInMetersPerSecond);

                base.DoUpdatePositionEvent(session, waypoint.Latitude, waypoint.Longitude, CurrentWalkingSpeed);

                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking(); // look for pokemon & hit stops
                }
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, destinaionCoordinate) >= 2);

            return(result);
        }
 ///<summary>
 ///  A constructor that takes in as a parameter geolocation information
 ///</summary>
 ///<param name = "geoLocation">
 ///  The location information used for astronomical calculating sun
 ///  times. </param>
 public AstronomicalCalendar(IGeoLocation geoLocation)
     : this(DateTime.Now, geoLocation)
 {
 }
 /// <summary>
 /// Calculates the distance from the this instance to destination location (in meters).
 /// </summary>
 /// <param name="src">The <see cref="IGeoLocation"/> to apply the method to.</param>
 /// <param name="dst">The destination location.</param>
 /// <returns>Returns the distance, in meters, from this instance to destination.</returns>
 /// <remarks>
 /// Note that we use the <a href="http://en.wikipedia.org/wiki/International_System_of_Units">International
 /// System of Units (SI)</a>; units of distance are specified in meters. If you want to use imperial system (e.g.
 /// miles, nautical miles, yards, foot and other units) you need to convert from/to meters. You can use the
 /// helper methods <see cref="GeoUtil.MilesToMeters"/> / <see cref="GeoUtil.MetersToMiles"/> and 
 /// <see cref="GeoUtil.YardsToMeters"/> / <see cref="GeoUtil.MetersToYards"/> for quick conversion.
 /// </remarks>
 /// <seealso cref="GeoUtil.MilesToMeters"/>
 /// <seealso cref="GeoUtil.MetersToMiles"/>
 /// <seealso cref="GeoUtil.YardsToMeters"/>
 /// <seealso cref="GeoUtil.MetersToYards"/>
 public static double DistanceTo(this IGeoLocation src, IGeoLocation dst)
 {
     return GeoUtil.DistanceTo(src, dst);
 }
Beispiel #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComplexZmanimCalendar"/> class.
 /// </summary>
 /// <param name="location">The location.</param>
 public ComplexZmanimCalendar(IGeoLocation location)
     : base(location)
 {
 }
Beispiel #27
0
 ///<summary>
 ///  A constructor that takes in as a parameter geolocation information
 ///</summary>
 ///<param name = "geoLocation">
 ///  The location information used for astronomical calculating sun
 ///  times. </param>
 public AstronomicalCalendar(IGeoLocation geoLocation)
     : this(DateTime.Now, geoLocation)
 {
 }
Beispiel #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GeoLocation"/> class.
 /// </summary>
 public GeoLocation()
 {
     nativeGeo = MXContainer.Resolve <IGeoLocation>();
 }
Beispiel #29
0
        public override async Task Walk(IGeoLocation targetLocation,
                                        Func <Task> functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken,
                                        double walkSpeed = 0.0)
        {
            base.OnStartWalking(session, targetLocation);

            var destinaionCoordinate = new GeoCoordinate(targetLocation.Latitude, targetLocation.Longitude);

            if (CurrentWalkingSpeed <= 0)
            {
                CurrentWalkingSpeed = session.LogicSettings.WalkingSpeedInKilometerPerHour;
            }
            if (session.LogicSettings.UseWalkingSpeedVariant && walkSpeed == 0)
            {
                CurrentWalkingSpeed = session.Navigation.VariantRandom(session, CurrentWalkingSpeed);
            }

            var rw = new Random();
            var speedInMetersPerSecond = (walkSpeed > 0 ? walkSpeed : CurrentWalkingSpeed) / 3.6;

            var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);

            var nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, destinaionCoordinate);


            var nextWaypointDistance   = speedInMetersPerSecond;
            var waypoint               = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);
            var requestSendDateTime    = DateTime.Now;
            var requestVariantDateTime = DateTime.Now;

            LocationUtils.UpdatePlayerLocationWithAltitude(session, waypoint, (float)speedInMetersPerSecond);

            double SpeedVariantSec = rw.Next(1000, 10000);

            base.DoUpdatePositionEvent(session, waypoint.Latitude, waypoint.Longitude, CurrentWalkingSpeed);

            do
            {
                cancellationToken.ThrowIfCancellationRequested();
                TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;
                var millisecondsUntilVariant =
                    (DateTime.Now - requestVariantDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils
                                              .CalculateDistanceInMeters(sourceLocation, destinaionCoordinate);

                if (currentDistanceToTarget < 40)
                {
                    if (speedInMetersPerSecond > SpeedDownTo)
                    {
                        speedInMetersPerSecond = SpeedDownTo;
                    }
                }

                if (session.LogicSettings.UseWalkingSpeedVariant && walkSpeed == 0)
                {
                    CurrentWalkingSpeed = session.Navigation.VariantRandom(session, CurrentWalkingSpeed);
                }

                speedInMetersPerSecond = (walkSpeed > 0 ? walkSpeed : CurrentWalkingSpeed) / 3.6;

                nextWaypointDistance = Math.Min(currentDistanceToTarget,
                                                millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing = LocationUtils.DegreeBearing(sourceLocation, destinaionCoordinate);
                var testeBear = LocationUtils.DegreeBearing(sourceLocation, new GeoCoordinate(40.780396, -73.974844));
                waypoint = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

                requestSendDateTime = DateTime.Now;
                LocationUtils.UpdatePlayerLocationWithAltitude(session, waypoint, (float)speedInMetersPerSecond);

                base.DoUpdatePositionEvent(session, waypoint.Latitude, waypoint.Longitude, CurrentWalkingSpeed);

                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking(); // look for pokemon
                }
            } while (LocationUtils.CalculateDistanceInMeters(sourceLocation, destinaionCoordinate) >= (new Random()).Next(1, 10));
        }
Beispiel #30
0
 /// <summary>
 /// Calculate the arc length distance between two locations using the Vincenty formula.
 /// In kilometers.
 /// From https://github.com/lmaslanka/Orthodromic-Distance-Calculator
 /// </summary>
 public static double VincentyDistanceFormula(IGeoLocation locationA, IGeoLocation locationB)
 {
     return AverageRadiusForSphericalApproximationOfEarth * Math.Atan(Math.Sqrt(((Math.Pow(Math.Cos(locationB.LatitudeRad) * Math.Sin(Diff(locationA.LongitudeRad, locationB.LongitudeRad)), 2)) + (Math.Pow((Math.Cos(locationA.LatitudeRad) * Math.Sin(locationB.LatitudeRad)) - (Math.Sin(locationA.LatitudeRad) * Math.Cos(locationB.LatitudeRad) * Math.Cos(Diff(locationA.LongitudeRad, locationB.LongitudeRad))), 2))) / ((Math.Sin(locationA.LatitudeRad) * Math.Sin(locationB.LatitudeRad)) + (Math.Cos(locationA.LatitudeRad) * Math.Cos(locationB.LatitudeRad) * Math.Cos(Diff(locationA.LongitudeRad, locationB.LongitudeRad))))));
 }
Beispiel #31
0
 ///<summary>
 ///  A constructor that takes a <seealso cref = "GeoLocation" /> as a parameter.
 ///</summary>
 ///<param name = "location">
 ///  the location </param>
 public ZmanimCalendar(IGeoLocation location)
     : base(location)
 {
 }
 /// <summary>
 /// Gets the geo distance in miles between this located object and a specified location.
 /// </summary>
 public static double?GetDistance(this IGeoLocated from, IGeoLocation to) => GetDistance(from.Get(l => l.GetLocation()), to);
        /// <summary>
        /// If the traveled distance is too far, ignore it
        /// </summary>
        /// <returns></returns>
        private bool Erroneous(IGeoLocation previous, IGeoLocation current, TimeSpan timeDelta)
        {
            var distanceDelta = GeoLocationTools.VincentyDistanceFormula(previous, current) * 1000.0;

            //meters per second
            var velocity = distanceDelta / timeDelta.TotalSeconds;

            //if the distance traveled > 45 m/s (100 mph), it is erroneous
            if (velocity > 45)
            {
                //TODO log this and figure out why the mobile phones are sending these trackpoints, or what is going wrong
                return true;
            }

            //if the point moved in the range of centimeters, it is erroneous
            if (Math.Abs(distanceDelta - 0) < 0.0000001)
            {
                return true;
            }

            return false;
        }
Beispiel #34
0
        /// <summary>
        /// Generate dynamic map with a border determined by nodes.
        /// </summary>
        public static void GenerateDynamicMap(IEnumerable <MapAreaInputs> inputs, MapInputs mapInputs, IGeoLocation center, string apiKey, string filePath)
        {
            // create folder if it doesn't exist
            new FileInfo(filePath).Directory.Create();

            var mapTemplate     = File.ReadAllText(Path.Combine("HtmlTemplates", "DynamicMapTemplate.html"));
            var polygonTemplate = File.ReadAllText(Path.Combine("HtmlTemplates", "PolygonTemplate.html"));

            var html = new StringBuilder(mapTemplate);

            html.Replace("/*key*/", apiKey);
            html.Replace("/*center*/", $"{center.Latitude}, {center.Longitude}");
            html.Replace("/*zoom*/", mapInputs.Zoom.ToString());
            html.Replace("/*width*/", mapInputs.Width.ToString());
            html.Replace("/*height*/", mapInputs.Height.ToString());

            var polygons = new List <string>();

            var num = 0;

            foreach (var input in inputs)
            {
                var polygon      = new StringBuilder(polygonTemplate);
                var nodesStrings = GetNodesStrings(input.Border, 16);

                polygon.Replace("/*num*/", num.ToString());
                polygon.Replace("/*color*/", $"\"{input.Color}\"");
                polygon.Replace("/*strokeOpacity*/", input.StrokeOpacity.ToString("0.00"));
                polygon.Replace("/*strokeWeight*/", input.StrokeWeight.ToString());
                polygon.Replace("/*fillOpacity*/", input.FillOpacity.ToString("0.00"));
                polygon.Replace("/*nodes*/", string.Join($",{Environment.NewLine}", nodesStrings));
                polygons.Add(polygon.ToString());

                num++;
            }

            html.Replace("/*polygons*/", string.Join(Environment.NewLine, polygons));

            File.WriteAllText(filePath, html.ToString());
        }
Beispiel #35
0
 /// <summary>
 /// Gets the geo distance in miles between this located object and a specified location.
 /// </summary>
 public static double?GetDistance(this IGeoLocated @this, IGeoLocation to) => GetDistance(@this?.GetLocation(), to);
 /// <summary>
 /// Calculates the distance from this instance to destination location (in meters).
 /// </summary>
 /// <param name="src">The <see cref="IGeoLocation"/> to apply the method to.</param>
 /// <param name="dst">The destination location.</param>
 /// <param name="radiusofearthinmeters">The radius of the earth in meters (default: 6371000).</param>
 /// <returns>Returns the distance, in meters, from this instance to destination.</returns>
 /// <remarks>
 /// Note that we use the <a href="http://en.wikipedia.org/wiki/International_System_of_Units">International
 /// System of Units (SI)</a>; units of distance are specified in meters. If you want to use imperial system (e.g.
 /// miles, nautical miles, yards, foot and other units) you need to convert from/to meters. You can use the
 /// helper methods <see cref="GeoUtil.MilesToMeters"/> / <see cref="GeoUtil.MetersToMiles"/> and 
 /// <see cref="GeoUtil.YardsToMeters"/> / <see cref="GeoUtil.MetersToYards"/> for quick conversion.
 /// </remarks>
 /// <seealso cref="GeoUtil.MilesToMeters"/>
 /// <seealso cref="GeoUtil.MetersToMiles"/>
 /// <seealso cref="GeoUtil.YardsToMeters"/>
 /// <seealso cref="GeoUtil.MetersToYards"/>
 public static double DistanceTo(this IGeoLocation src, IGeoLocation dst, double radiusofearthinmeters)
 {
     return GeoUtil.DistanceTo(src, dst, radiusofearthinmeters);
 }
Beispiel #37
0
 /// <summary>
 /// Gets the geo distance in miles between this location and a specified located object.
 /// </summary>
 public static double?GetDistance(this IGeoLocation @this, IGeoLocated to) => GetDistance(@this, to?.GetLocation());
Beispiel #38
0
 ///<summary>
 ///  A constructor that takes in as a parameter geolocation information
 ///</summary>
 ///<param name="dateTime">The DateTime</param>
 ///<param name = "geoLocation">
 ///  The location information used for astronomical calculating sun
 ///  times. </param>
 public AstronomicalCalendar(DateTime dateTime, IGeoLocation geoLocation)
     : this(new DateWithLocation(dateTime, geoLocation))
 {
 }
Beispiel #39
0
        /// <summary>
        /// Calculates a new GeoLocation for the given
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public IGeoLocation CalcOffsetLocation(IGeoLocation origin, double dx, double dy)
        {
            var result = CalculateOffset(origin.Latitude, origin.Latitude, dx, dy);

            return(new GeoFactory().CreateLocation(result.latitude, result.longitude));
        }
Beispiel #40
0
 /// <summary>
 /// A constructor that takes a <seealso cref="GeoLocation"/> as a parameter.
 /// </summary>
 /// <param name="date">The date.</param>
 /// <param name="location">the location</param>
 public ZmanimCalendar(DateTime date, IGeoLocation location)
     : base(date, location)
 {
 }
Beispiel #41
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DateWithLocation"/> class.
 /// </summary>
 /// <param name="date">The date.</param>
 /// <param name="location"></param>
 public DateWithLocation(DateTime date, IGeoLocation location)
 {
     Date     = date;
     Location = location;
 }
Beispiel #42
0
        public override async Task Walk(IGeoLocation targetLocation,
                                        Func <Task> functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken,
                                        double walkSpeed = 0.0)
        {
            var curLocation          = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
            var destinaionCoordinate = new GeoCoordinate(targetLocation.Latitude, targetLocation.Longitude);

            var dist = LocationUtils.CalculateDistanceInMeters(curLocation, destinaionCoordinate);

            if (dist >= 100)
            {
                var nextWaypointDistance = dist * 70 / 100;
                var nextWaypointBearing  = LocationUtils.DegreeBearing(curLocation, destinaionCoordinate);

                var waypoint = LocationUtils.CreateWaypoint(curLocation, nextWaypointDistance, nextWaypointBearing);
                var sentTime = DateTime.Now;

                // We are setting speed to 0, so it will be randomly generated speed.
                LocationUtils.UpdatePlayerLocationWithAltitude(session, waypoint, 0);
                base.DoUpdatePositionEvent(session, waypoint.Latitude, waypoint.Longitude, walkSpeed, 0);

                do
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
                    var millisecondsUntilGetUpdatePlayerLocationResponse =
                        (DateTime.Now - sentTime).TotalMilliseconds;

                    curLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                    var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(curLocation, destinaionCoordinate);

                    dist = LocationUtils.CalculateDistanceInMeters(curLocation, destinaionCoordinate);

                    if (dist >= 100)
                    {
                        nextWaypointDistance = dist * 70 / 100;
                    }
                    else
                    {
                        nextWaypointDistance = dist;
                    }

                    nextWaypointBearing = LocationUtils.DegreeBearing(curLocation, destinaionCoordinate);
                    waypoint            = LocationUtils.CreateWaypoint(curLocation, nextWaypointDistance, nextWaypointBearing);
                    sentTime            = DateTime.Now;
                    // We are setting speed to 0, so it will be randomly generated speed.
                    LocationUtils.UpdatePlayerLocationWithAltitude(session, waypoint, 0);
                    base.DoUpdatePositionEvent(session, waypoint.Latitude, waypoint.Longitude, walkSpeed);


                    if (functionExecutedWhileWalking != null)
                    {
                        await functionExecutedWhileWalking(); // look for pokemon
                    }
                } while (LocationUtils.CalculateDistanceInMeters(curLocation, destinaionCoordinate) >= 10);
            }
            else
            {
                // We are setting speed to 0, so it will be randomly generated speed.
                LocationUtils.UpdatePlayerLocationWithAltitude(session, targetLocation.ToGeoCoordinate(), 0);
                base.DoUpdatePositionEvent(session, targetLocation.Latitude, targetLocation.Longitude, walkSpeed);
                if (functionExecutedWhileWalking != null)
                {
                    await functionExecutedWhileWalking(); // look for pokemon
                }
            }
        }
Beispiel #43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DateWithLocation"/> class.
 /// </summary>
 /// <param name="date">The date.</param>
 /// <param name="location"></param>
 public DateWithLocation(DateTime date, IGeoLocation location)
 {
     Date = date;
     Location = location;
 }
 /// <summary>
 /// Gets the geo distance in miles between this location and a specified located object.
 /// </summary>
 public static double?GetDistance(this IGeoLocation from, IGeoLocated to)
 {
     return(GetDistance(from, to.Get(l => l.GetLocation())));
 }
Beispiel #45
0
 /// <summary>
 /// Ctor
 /// </summary>
 public DirectionGeoLine(IGeoLocation point, DirectionEnum direction)
 {
     this.point = point;
     multLat    = direction.MultY();
     multLong   = direction.MultX();
 }
Beispiel #46
0
        public Task <PlayerUpdateResponse> RedirectToNextFallbackStrategy(ILogicSettings logicSettings, IGeoLocation targetLocation, Func <Task> functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken, double walkSpeed = 0.0)
        {
            // If we need to fall-back, then blacklist current strategy for 1 hour.
            session.Navigation.BlacklistStrategy(this.GetType());

            IWalkStrategy nextStrategy = session.Navigation.GetStrategy(logicSettings);

            return(nextStrategy.Walk(targetLocation, functionExecutedWhileWalking, session, cancellationToken));
        }
Beispiel #47
0
 /// <summary>
 /// Calculates the distance from the source to destination location (in meters).
 /// </summary>
 /// <param name="src">The source location.</param>
 /// <param name="dest">The destination location.</param>
 /// <param name="radiusofearth">The radius of the earth in meters (default: 6371000).</param>
 /// <returns>Returns the distance, in meters, from source to destination.</returns>
 /// <remarks>
 /// Note that we use the <a href="http://en.wikipedia.org/wiki/International_System_of_Units">International
 /// System of Units (SI)</a>; units of distance are specified in meters. If you want to use imperial system (e.g.
 /// miles, nautical miles, yards, foot and whathaveyou's) you need to convert from/to meters. You can use the
 /// helper methods <see cref="GeoUtil.MilesToMeters"/> / <see cref="GeoUtil.MetersToMiles"/> and 
 /// <see cref="GeoUtil.YardsToMeters"/> / <see cref="GeoUtil.MetersToYards"/> for quick conversion.
 /// </remarks>
 internal static double DistanceTo(IGeoLocation src, IGeoLocation dest, double radiusofearth = RADIUSOFEARTH)
 {
     double dLat = GeoUtil.Deg2Rad(dest.Latitude - src.Latitude);
     double dLon = GeoUtil.Deg2Rad(dest.Longitude - src.Longitude);
     return (radiusofearth / 1000) * (2 * Math.Asin(Math.Min(1, Math.Sqrt(Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(GeoUtil.Deg2Rad(src.Latitude)) * Math.Cos(GeoUtil.Deg2Rad(dest.Latitude)) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2)))));
 }