コード例 #1
0
        public IActionResult SearchNearestPartner(double lat, double lgn)
        {
            var queryPosition = new Position(lat, lgn);
            var distance      = 0.0;
            var lessDistant   = double.MaxValue;

            PartnerViewModel nearestPartner = null;

            _partnerAppService.GetAll().ToList().ForEach(partner =>
            {
                if (GeoLocationHelper.IsPointInMultiPolygon(queryPosition, partner.DeserializedCoverageArea))
                {
                    distance = GeoLocationHelper.GetDistance(partner.DeserializedAddress.Coordinates, queryPosition);
                    if (distance < lessDistant)
                    {
                        lessDistant    = distance;
                        nearestPartner = partner;
                    }
                }
            });

            if (nearestPartner != null)
            {
                return(Response(nearestPartner));
            }
            return(Response("No Partner found with the informed coordinates!"));
        }
        public void GetDistance_Sucessfully(double basePositionLatitude, double basePositionLongitude, double testPositionLatitude, double testPositionLongitude, double expectedDistance)
        {
            Position basePosition = new Position(basePositionLatitude, basePositionLongitude);
            Position testPosition = new Position(testPositionLatitude, testPositionLongitude);

            var distance = GeoLocationHelper.GetDistance(basePosition, testPosition);

            distance.Should().Be(expectedDistance);
        }