public static HashSet <GeoHashQuery> QueriesAtLocation(GeoPoint location, double radius) { var queryBits = Math.Max(1, Utils.BitsForBoundingBox(location, radius)); var geoHashPrecision = (int)Math.Ceiling((float)queryBits / Base32Utils.BitsPerBase32Char); var latitude = location.Latitude; var longitude = location.Longitude; var latitudeDegrees = radius / Constants.MetersPerDegreeLatitude; var latitudeNorth = Math.Min(90, latitude + latitudeDegrees); var latitudeSouth = Math.Max(-90, latitude - latitudeDegrees); var longitudeDeltaNorth = GeoUtils.DistanceToLongitudeDegrees(radius, latitudeNorth); var longitudeDeltaSouth = GeoUtils.DistanceToLongitudeDegrees(radius, latitudeSouth); var longitudeDelta = Math.Max(longitudeDeltaNorth, longitudeDeltaSouth); var queries = new HashSet <GeoHashQuery>(); var geoHash = new GeoHash(latitude, longitude, geoHashPrecision); var geoHashW = new GeoHash(latitude, GeoUtils.WrapLongitude(longitude - longitudeDelta), geoHashPrecision); var geoHashE = new GeoHash(latitude, GeoUtils.WrapLongitude(longitude + longitudeDelta), geoHashPrecision); var geoHashN = new GeoHash(latitudeNorth, longitude, geoHashPrecision); var geoHashNw = new GeoHash(latitudeNorth, GeoUtils.WrapLongitude(longitude - longitudeDelta), geoHashPrecision); var geoHashNE = new GeoHash(latitudeNorth, GeoUtils.WrapLongitude(longitude + longitudeDelta), geoHashPrecision); var geoHashS = new GeoHash(latitudeSouth, longitude, geoHashPrecision); var geoHashSW = new GeoHash(latitudeSouth, GeoUtils.WrapLongitude(longitude - longitudeDelta), geoHashPrecision); var geoHashSE = new GeoHash(latitudeSouth, GeoUtils.WrapLongitude(longitude + longitudeDelta), geoHashPrecision); queries.Add(QueryForGeoHash(geoHash, queryBits)); queries.Add(QueryForGeoHash(geoHashE, queryBits)); queries.Add(QueryForGeoHash(geoHashW, queryBits)); queries.Add(QueryForGeoHash(geoHashN, queryBits)); queries.Add(QueryForGeoHash(geoHashNE, queryBits)); queries.Add(QueryForGeoHash(geoHashNw, queryBits)); queries.Add(QueryForGeoHash(geoHashS, queryBits)); queries.Add(QueryForGeoHash(geoHashSE, queryBits)); queries.Add(QueryForGeoHash(geoHashSW, queryBits)); // Join queries bool didJoin; do { GeoHashQuery query1 = null; GeoHashQuery query2 = null; foreach (var query in queries) { foreach (var other in queries.Where(other => query != other && query.CanJoinWith(other))) { query1 = query; query2 = other; break; } } if (query1 != null && query2 != null) { queries.Remove(query1); queries.Remove(query2); queries.Add(query1.JoinWith(query2)); didJoin = true; } else { didJoin = false; } } while (didJoin); return(queries); }