Пример #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);
        }
Пример #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 });
        }
Пример #3
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);
        }