Ejemplo n.º 1
0
 public ShelterCardModel(Data.Entities.Models.Shelter shelter, Geolocation userGeolocation)
 {
     Id               = shelter.Id;
     Name             = shelter.Name;
     WebsiteUrl       = shelter.WebsiteUrl;
     City             = shelter.City;
     Address          = shelter.Address;
     ContactPhone     = shelter.ContactPhone;
     ContactEmail     = shelter.ContactEmail;
     DistanceFromUser = GeolocationHelper.GetDistance(shelter.Geolocation, userGeolocation);
 }
        public void distanceBetweenNewyorkAndNewyorkShouldBe0()
        {
            var newyorkCoord = new Coordinate()
            {
                Latitude  = _newYork.Lat,
                Longitude = _newYork.Long
            };

            var result   = GeolocationHelper.GetDistance(newyorkCoord, newyorkCoord);
            var expected = 0;

            Assert.Equal(expected, result);
        }
        public void distanceBetweenMontrealAndNewyorkShouldBe535km()
        {
            var montrealCoord = new Coordinate()
            {
                Latitude  = _montreal.Lat,
                Longitude = _montreal.Long
            };

            var newyorkCoord = new Coordinate()
            {
                Latitude  = _newYork.Lat,
                Longitude = _newYork.Long
            };

            var result   = GeolocationHelper.GetDistance(montrealCoord, newyorkCoord);
            var expected = 534209.131234364;

            Assert.Equal(expected, result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Calculate the score of a city based on the searched coordinates.
        /// </summary>
        /// <param name="city">City</param>
        /// <param name="latitude">Latitude</param>
        /// <param name="longitude">Longitude</param>
        /// <returns>City score based on the searched coordinates</returns>
        private double GetCoordinateScore(City city, double latitude, double longitude)
        {
            var firstLocation = new Coordinate()
            {
                Latitude  = city.Lat,
                Longitude = city.Long
            };

            var secondLocation = new Coordinate()
            {
                Latitude  = latitude,
                Longitude = longitude
            };

            var distance         = GeolocationHelper.GetDistance(firstLocation, secondLocation);
            var farthestDistance = 1500000;

            return(distance < farthestDistance
                ? (farthestDistance - distance) / farthestDistance
                : 0);
        }