Example #1
0
    /**
     * This process is executed each 10 seconds. First, the location of the device is updated,
     * after that, we obtain the map. Later, the go through the locations and we configure the
     * UI depending if we have a location to show or a near location.
     */
    private IEnumerator refreshLocation()
    {
        while (true)
        {
            UnityEngine.Debug.Log("Refreshing location of the device.");
            var coordactual = new Location(GPS.Instance.latitude, GPS.Instance.longitude, 0);
            StartCoroutine("obtainMap");

            foreach (Location l in locations)
            {
                var distance = CoordinatesDistanceExtensions.DistanceTo(l, coordactual);
                if (distance < 20 && actualRep == null) // less 20 meters show
                {
                    UnityEngine.Debug.Log("Location detected at " + distance + " meters.");
                    obtainAllInfo(l.id);
                    obtainRepVideo(l.id);
                    obtainRepImage(l.id);
                    isShowing = true;
                }
                else if (distance < 200) // less 200 meters show as near location
                {
                    UnityEngine.Debug.Log("Near location detected at " + distance + " meters.");
                    obtainLocationImage(l);
                    nearLocations.Add(l);
                    l.distance = distance;
                }
                else if (!isShowing)
                {
                    actualRep = null;
                }
            }

            configureNearLocations();
            if (actualRep == null)
            {
                panelShow.SetActive(false);
            }
            else
            {
                configureUI();
            }

            yield return(new WaitForSeconds(10.0f)); //Wait 10 seconds
        }
    }
Example #2
0
        /**
         * Domain logic responsible for calculating distance and finding the closest few scooters to a given coordinate.
         * First, we get all Scooters that's available in the database at the current moment.
         * Next, we iterate through all the Scooters available and calculate their distance.
         * If the distance is smaller than the specified distance (termed radius),
         * the Scooter will be added to a List holding all nearest scooters.
         * At the same time, their distance and UUID will be saved in a List of Tuples, which will be sorted.
         * We will then find the UUID of scooters from the shortest distance first and add these Scooters to another
         * list (called constrainNearestScooters). constrainNearestScooters will then hold a
         * specific number of closest scooters to the given point and will be returned by this function.
         */
        public IEnumerable <ScooterDomainModel> GetClosest(ScooterClosestDomainModel scooterClosestDomainModel)
        {
            Coordinates centreCoordinate        = scooterClosestDomainModel.CentreCoordinate;
            int         nearestNumberOfScooters = scooterClosestDomainModel.NearestNumberOfScooters;
            int         radius = scooterClosestDomainModel.Radius;

            IEnumerable <ScooterDomainModel> allScooters                  = _repository.GetAll().Result;
            List <ScooterDomainModel>        allNearestScooters           = new List <ScooterDomainModel>();
            List <ScooterDomainModel>        constrainNearestScooters     = new List <ScooterDomainModel>();
            List <Tuple <double, Guid> >     distanceOfAllNearestScooters = new List <Tuple <double, Guid> >();

            foreach (ScooterDomainModel scooter in allScooters)
            {
                double distance = CoordinatesDistanceExtensions.GetDistance(
                    scooter.Longitude,
                    scooter.Latitude,
                    centreCoordinate.Longitude,
                    centreCoordinate.Latitude);
                if (!(distance <= radius))
                {
                    continue;
                }
                allNearestScooters.Add(scooter);
                distanceOfAllNearestScooters.Add(new Tuple <double, Guid>(distance, scooter.Id));
            }

            distanceOfAllNearestScooters.Sort((x, y)
                                              => x.Item1.CompareTo(y.Item1));

            while (nearestNumberOfScooters > 0 && distanceOfAllNearestScooters.Any())
            {
                var initialElement = distanceOfAllNearestScooters.First();
                ScooterDomainModel desiredScooter = allNearestScooters.Find(model =>
                                                                            model.Id.Equals(initialElement.Item2));
                constrainNearestScooters.Add(desiredScooter);
                nearestNumberOfScooters--;
                distanceOfAllNearestScooters.Remove(initialElement);
            }
            return(constrainNearestScooters);
        }
Example #3
0
 public async Task <IEnumerable <Band> > BandsInDistance(Coordinates coordinates, double distance)
 {
     return(await _context.Bands.Where(x => CoordinatesDistanceExtensions.DistanceTo(coordinates, new Coordinates(x.Latitude, x.Longitude)) < distance).ToListAsync());
 }
Example #4
0
 public IEnumerable <UserAccount> UsersInDistance(Coordinates coordinates, double distance)
 {
     return(_context.UserAccounts.Where(x => CoordinatesDistanceExtensions.DistanceTo(coordinates, new Coordinates(x.Latitude, x.Longitude)) < distance));
 }