public static GeoHashQuery queryForGeoHash(GeoHash geohash, int bits) { string hash = geohash.getGeoHashString(); int precision = (int)Math.Ceiling((double)bits / Base32Utils.BITS_PER_BASE32_CHAR); if (hash.Length < precision) { return(new GeoHashQuery(hash, hash + "~")); } hash = hash.Substring(0, precision); string baseS = hash.Substring(0, hash.Length - 1); int lastValue = Base32Utils.base32CharToValue(hash[(hash.Length - 1)]); int significantBits = bits - (baseS.Length * Base32Utils.BITS_PER_BASE32_CHAR); int unusedBits = (Base32Utils.BITS_PER_BASE32_CHAR - significantBits); // delete unused bits int startValue = (lastValue >> unusedBits) << unusedBits; int endValue = startValue + (1 << unusedBits); string startHash = baseS + Base32Utils.valueToBase32Char(startValue); string endHash; if (endValue > 31) { endHash = baseS + "~"; } else { endHash = baseS + Base32Utils.valueToBase32Char(endValue); } return(new GeoHashQuery(startHash, endHash)); }
public bool containsGeoHash(GeoHash hash) { string hashStr = hash.getGeoHashString(); return(this.startValue.CompareTo(hashStr) <= 0 && this.endValue.CompareTo(hashStr) > 0); }