/// <summary>
 /// Gets the point.
 /// </summary>
 /// <param name="point">The point.</param>
 /// <param name="distanceInKm">The distance in km.</param>
 /// <param name="bearing">The bearing.</param>
 /// <returns>New coordinates</returns>
 private static Coordinates GetPoint(Coordinates point, double distanceInKm, double bearing)
 {
     Coordinates coordinateToReturn = new Coordinates(true);
     coordinateToReturn.Latitude = Math.Asin(Math.Sin(point.Latitude) * Math.Cos(distanceInKm / GeoAreaProvider.RadiusOfEarth) + Math.Cos(point.Latitude) * Math.Sin(distanceInKm / GeoAreaProvider.RadiusOfEarth) * Math.Cos(bearing));
     coordinateToReturn.Longitude = point.Longitude + Math.Atan2(Math.Sin(bearing) * Math.Sin(distanceInKm / GeoAreaProvider.RadiusOfEarth) * Math.Cos(point.Latitude), Math.Cos(distanceInKm / GeoAreaProvider.RadiusOfEarth) - Math.Sin(point.Latitude) * Math.Sin(coordinateToReturn.Latitude));
     return coordinateToReturn;
 }
        /// <summary>
        /// Gets the boundary.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="distanceInKm">The distance in km.</param>
        /// <param name="topLeft">The top left.</param>
        /// <param name="bottomRight">The bottom right.</param>
        void IGeoAreaProvider.GetBoundary(Coordinates point, double distanceInKm, out Coordinates topLeft, out Coordinates bottomRight)
        {
            if (!point.IsRadians)
            {
                point.ConvertToRadians();
            }

            double bearing = 0;
            Coordinates top = GeoAreaProvider.GetPoint(point, distanceInKm, bearing);

            bearing = Math.PI / 2;
            Coordinates right = GeoAreaProvider.GetPoint(point, distanceInKm, bearing);

            bearing = Math.PI;
            Coordinates bottom = GeoAreaProvider.GetPoint(point, distanceInKm, bearing);

            bearing = Math.PI * 3 / 2;
            Coordinates left = GeoAreaProvider.GetPoint(point, distanceInKm, bearing);

            topLeft = new Coordinates(true);
            bottomRight = new Coordinates(true);

            topLeft.Latitude = top.Latitude;
            topLeft.Longitude = left.Longitude;

            bottomRight.Latitude = bottom.Latitude;
            bottomRight.Longitude = right.Longitude;

            topLeft.ConvertToDegrees();
            bottomRight.ConvertToDegrees();
        }
        /// <summary>
        /// Gets the agents by ids query.
        /// </summary>
        /// <param name="userIds">The user ids.</param>
        /// <returns>Query with correct length of userIds</returns>
        public static string GetUsersByIdsQuery(List<string> userIds, Coordinates coordinates = null)
        {
            List<string> parameterNames = new List<string>();
            for (int i = 0; i < userIds.Count; i++)
            {
                parameterNames.Add("@userId" + i);
            }

            string latLngString = string.Empty;
            if(coordinates != null)
            {
                latLngString = string.Format(@"AND (AreaOfServiceBottomRightLat < {0} AND {0} < AreaOfServiceTopLeftLat)", "@Lat");
                latLngString += string.Format(@"AND (AreaOfServiceTopLeftLng < {0} AND {0} < AreaOfServiceBottomRightLng)", "@Lng");
            }

            return string.Format(SqlQueries.GetUsersByIds, string.Join(",", parameterNames), latLngString);
        }