Ejemplo n.º 1
0
        public async Task CreateGeofence()
        {
            // If Geofence is created do nothing
            if (!string.IsNullOrEmpty(_currentGeofenceUdId))
            {
                return;
            }
            var currentPosition = new GeoCoordinateModel(Constants.FakeUserDefaultLatitude, Constants.FakeUserDefaultLongitude);
            var firstPosition   = currentPosition.CalculateDerivedPosition(Constants.GeofenceRatioInMeters, -90);
            var secondPosition  = currentPosition.CalculateDerivedPosition(Constants.GeofenceRatioInMeters, 0);
            var thirdPosition   = currentPosition.CalculateDerivedPosition(Constants.GeofenceRatioInMeters, 90);
            var fourthPosition  = currentPosition.CalculateDerivedPosition(Constants.GeofenceRatioInMeters, 180);

            var polygonCoordinates = new List <List <double> > {
                new List <double> {
                    firstPosition.Longitude, firstPosition.Latitude
                },
                new List <double> {
                    secondPosition.Longitude, secondPosition.Latitude
                },
                new List <double> {
                    thirdPosition.Longitude, thirdPosition.Latitude
                },
                new List <double> {
                    fourthPosition.Longitude, fourthPosition.Latitude
                },
                new List <double> {
                    firstPosition.Longitude, firstPosition.Latitude
                }
            };
            var geometry = new UploadGeofenceGeometryModel();

            geometry.Coordinates.Add(polygonCoordinates);
            await this.UploadGeofence(geometry);
        }
Ejemplo n.º 2
0
        public async Task ResetUserGeoposition()
        {
            var currentPosition = new GeoCoordinateModel(Constants.FakeUserDefaultLatitude, Constants.FakeUserDefaultLongitude);
            var ratioDistance   = Constants.GeofenceRatioInMeters * 2;
            var userPosition    = currentPosition.CalculateDerivedPosition(ratioDistance, -90);

            await NotifyUserGeoposition(new UserLocationModel { Latitude = userPosition.Latitude, Longitude = userPosition.Longitude });
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GeoCoordinate(Guid mapSegmentId)
        {
            var mapSegment = await _bll.MapSegments.FindAsync(mapSegmentId);

            if (mapSegment == null)
            {
                return(NotFound());
            }

            var model = new GeoCoordinateModel();

            model.MapSegmentId   = mapSegment.Id;
            model.MapSegmentName = mapSegment.Name;

            return(View(model));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Calculates the end-point from a given source at a given range (meters) and bearing (degrees).
        /// This methods uses simple geometry equations to calculate the end-point.
        /// </summary>
        /// <param name="source">Point of origin</param>
        /// <param name="range">Range in meters</param>
        /// <param name="bearing">Bearing in degrees</param>
        /// <returns>End-point from the source given the desired range and bearing.</returns>
        public static GeoCoordinateModel CalculateDerivedPosition(this GeoCoordinateModel source, double range, double bearing)
        {
            var latA            = source.Latitude * DegreesToRadians;
            var lonA            = source.Longitude * DegreesToRadians;
            var angularDistance = range / EarthRadius;
            var trueCourse      = bearing * DegreesToRadians;

            var lat = Math.Asin(
                Math.Sin(latA) * Math.Cos(angularDistance) +
                Math.Cos(latA) * Math.Sin(angularDistance) * Math.Cos(trueCourse));

            var dlon = Math.Atan2(
                Math.Sin(trueCourse) * Math.Sin(angularDistance) * Math.Cos(latA),
                Math.Cos(angularDistance) - Math.Sin(latA) * Math.Sin(lat));

            var lon = ((lonA + dlon + Math.PI) % (Math.PI * 2)) - Math.PI;

            return(new GeoCoordinateModel(lat * RadiansToDegrees, lon * RadiansToDegrees));
        }
Ejemplo n.º 5
0
        public UserLocationModel UpdateUserLocation(string userId, UpdateUserLocationModel updateUserLocation)
        {
            ClearExpiredUsers();
            var storedUserLocation = UsersLocations.FirstOrDefault(user => string.Equals(user.Id, userId, StringComparison.OrdinalIgnoreCase));

            if (storedUserLocation == null)
            {
                throw new UserNotFoundException($"User not found with the id: {userId}");
            }

            var currentPosition            = new GeoCoordinateModel(storedUserLocation.Latitude, storedUserLocation.Longitude);
            GeoCoordinateModel newPosition = null;

            switch (updateUserLocation.Direction)
            {
            case Direction.North:
                newPosition = currentPosition.CalculateDerivedPosition(_azureMapsOptions.UserStepDistanceInMeters, 0);
                break;

            case Direction.South:
                newPosition = currentPosition.CalculateDerivedPosition(_azureMapsOptions.UserStepDistanceInMeters, 180);
                break;

            case Direction.West:
                newPosition = currentPosition.CalculateDerivedPosition(_azureMapsOptions.UserStepDistanceInMeters, -90);
                break;

            case Direction.East:
                newPosition = currentPosition.CalculateDerivedPosition(_azureMapsOptions.UserStepDistanceInMeters, 90);
                break;
            }

            storedUserLocation.Latitude    = newPosition.Latitude;
            storedUserLocation.Longitude   = newPosition.Longitude;
            storedUserLocation.LastUpdated = DateTime.Now;
            return(storedUserLocation);
        }
Ejemplo n.º 6
0
        public async Task MoveUserInsideGeofence()
        {
            var currentPosition = new GeoCoordinateModel(Constants.FakeUserDefaultLatitude, Constants.FakeUserDefaultLongitude);

            await NotifyUserGeoposition(new UserLocationModel { Latitude = currentPosition.Latitude, Longitude = currentPosition.Longitude });
        }