コード例 #1
0
        public void AddLocationFilter(ref Dictionary <string, object> parameters, IMapAPIReadService mapAPIReadService, ref IQueryBuilder queryBuilder, char tablename, string columnname, string countryName = null,
                                      string municipalityName = null, string cityName = null, int?locationRange = null)
        {
            if (!(cityName is null) && !(locationRange is null))
            {
                // Use Map API
                Coordinates coordinates = mapAPIReadService.GetMapCoordinates(cityName, countryName, municipalityName);

                if (!(coordinates is null))
                {
                    parameters.Add("@latitude", coordinates.Latitude);
                    parameters.Add("@longitude", coordinates.Longitude);
                    parameters.Add("@rangeKm", locationRange);

                    queryBuilder.AddSelect(String.Format(@"(
                        6371 * acos(
                          cos(radians(@latitude))
                          * cos(radians({0}.{1}_breedtegraad))
                          * cos(radians({0}.{1}_lengtegraad) - radians(@longitude))
                          + sin(radians(@latitude))
                          * sin(radians({0}.{1}_breedtegraad))
                        )) as distance", tablename, columnname));
                    queryBuilder.AddHaving("distance < @rangeKm");
                }