public bool ContainsGeoHash(GeoHash hash) { var hashStr = hash.GetGeoHashString(); return(Compare(_startValue, hashStr, StringComparison.Ordinal) <= 0 && Compare(_endValue, hashStr, StringComparison.Ordinal) > 0); }
public static GeoHashQuery QueryForGeoHash(GeoHash geohash, int bits) { var hash = geohash.GetGeoHashString(); var precision = (int)Math.Ceiling((double)bits / Base32Utils.BitsPerBase32Char); if (hash.Length < precision) { return(new GeoHashQuery(hash, hash + "~")); } hash = hash.Substring(0, precision); var hashBase = hash.Substring(0, hash.Length - 1); var lastValue = Base32Utils.Base32CharToValue(hash[hash.Length - 1]); var significantBits = bits - hashBase.Length * Base32Utils.BitsPerBase32Char; var unusedBits = Base32Utils.BitsPerBase32Char - significantBits; // delete unused bits var startValue = (lastValue >> unusedBits) << unusedBits; var endValue = startValue + (1 << unusedBits); var startHash = hashBase + Base32Utils.ValueToBase32Char(startValue); var endHash = endValue > 31 ? hashBase + "~" : hashBase + Base32Utils.ValueToBase32Char(endValue); return(new GeoHashQuery(startHash, endHash)); }