コード例 #1
0
ファイル: ShelterCardModel.cs プロジェクト: fdoljanin/saponja
 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);
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #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);
        }