@Test public void testStepsBetween() { GeoHash bl = GeoHash.withBitPrecision(37.7, -122.52, 35); GeoHash ur = GeoHash.withBitPrecision(37.84, -122.35, 35); long steps = GeoHash.stepsBetween(bl, bl); assertEquals(steps, 0); steps = GeoHash.stepsBetween(bl, bl.next(4)); assertEquals(steps, 4); BoundingBoxGeoHashIterator iter = new BoundingBoxGeoHashIterator(new TwoGeoHashBoundingBox(bl, ur)); int count = 0; while (iter.hasNext()) { iter.next(); count++; } assertEquals(12875, count); int allHashes = 0; int inBbox = 1; int latMore = 0; int lonMore = 0; int bothMore = 0; int latLess = 0; int lonLess = 0; int bothLess = 0; int latLessLonMore = 0; int latMoreLonLess = 0; GeoHash idx = bl; BoundingBox iterBbox = iter.getBoundingBox().getBoundingBox(); while (idx.compareTo(ur) < 0) { idx = idx.next(); allHashes++; if (iterBbox.contains(idx.getPoint())) { inBbox++; } boolean latIsMore = false; boolean latIsLess = false; if (idx.getPoint().getLatitude() > iterBbox.getMaxLat()) { latIsMore = true; latMore++; } else if (idx.getPoint().getLatitude() < iterBbox.getMinLat()) { latIsLess = true; latLess++; } if (idx.getPoint().getLongitude() > iterBbox.getMaxLon()) { lonMore++; if (latIsMore) { bothMore++; } if (latIsLess) { latLessLonMore++; } } else if (idx.getPoint().getLongitude() < iterBbox.getMinLon()) { lonLess++; if (latIsLess) { bothLess++; } if (latIsMore) { latMoreLonLess++; } } } steps = GeoHash.stepsBetween(bl, ur); assertEquals(48472, steps); assertEquals(steps, allHashes); assertEquals(count, inBbox); assertEquals(14938, latMore); assertEquals(640, lonMore); assertEquals(0, bothMore); assertEquals(7680, latLess); assertEquals(24391, lonLess); assertEquals(0, bothLess); assertEquals(240, latLessLonMore); assertEquals(11811, latMoreLonLess); assertEquals(steps, lonLess + latLess + latMore + lonMore + inBbox - latLessLonMore - latMoreLonLess - 1); }
public static long stepsBetween(GeoHash one, GeoHash two) { if (one.significantBits() != two.significantBits()) { throw new IllegalArgumentException( "It is only valid to compare the number of steps between two hashes if they have the same number of significant bits"); } return two.ord() - one.ord(); }
GeoHash implements Comparable<GeoHash>, Serializable { public static long stepsBetween(GeoHash one, GeoHash two) { if (one.significantBits() != two.significantBits()) { throw new IllegalArgumentException( "It is only valid to compare the number of steps between two hashes if they have the same number of significant bits"); } return two.ord() - one.ord(); } }
GeoHash implements Comparable<GeoHash>, Serializable { public static long stepsBetween(GeoHash one, GeoHash two) { if (one.significantBits() != two.significantBits()) { throw new IllegalArgumentException( "It is only valid to compare the number of steps between two hashes if they have the same number of significant bits"); } return two.ord() - one.ord(); } protected  GeoHash(); private  GeoHash(double latitude, double longitude, int desiredPrecision); }
GeoHash implements Comparable<GeoHash>, Serializable { public static long stepsBetween(GeoHash one, GeoHash two) { if (one.significantBits() != two.significantBits()) { throw new IllegalArgumentException( "It is only valid to compare the number of steps between two hashes if they have the same number of significant bits"); } return two.ord() - one.ord(); } protected  GeoHash(); private  GeoHash(double latitude, double longitude, int desiredPrecision); static void main(String[] args); static int getBitsToShift(int b1, int b2); static GeoHash withUnprecisionOfDistanceInMeter(double centerLat, double centerLong, double distanceInMeter); static GeoHash withCharacterPrecision(double latitude, double longitude, int numberOfCharacters); static GeoHash withBitPrecision(double latitude, double longitude, int numberOfBits); static GeoHash fromBinaryString(String binaryString); static GeoHash fromGeohashString(String geohash); static GeoHash fromIntValue(int hashVal); static GeoHash fromLongValue(long hashVal, int significantBits); GeoHash next(int step); GeoHash next(); GeoHash prev(); long ord(); static GeoHash fromOrd(long ord, int significantBits); static long stepsBetween(GeoHash one, GeoHash two); GeoHash[] getAdjacent(); int significantBits(); long longValue(); int intValue(); String toBase32(); boolean within(GeoHash boundingBox); boolean contains(WGS84Point point); WGS84Point getPoint(); WGS84Point getBoundingBoxCenterPoint(); BoundingBox getBoundingBox(); boolean enclosesCircleAroundPoint(WGS84Point point, double radius); GeoHash getNorthernNeighbour(); GeoHash getSouthernNeighbour(); GeoHash getEasternNeighbour(); GeoHash getWesternNeighbour(); @Override String toString(); String toBinaryString(); @Override boolean equals(Object obj); @Override int hashCode(); @Override int compareTo(GeoHash o); static double distFromInMeter(double lat1, double lng1, double lat2, double lng2); }
GeoHash implements Comparable<GeoHash>, Serializable { public static long stepsBetween(GeoHash one, GeoHash two) { if (one.significantBits() != two.significantBits()) { throw new IllegalArgumentException( "It is only valid to compare the number of steps between two hashes if they have the same number of significant bits"); } return two.ord() - one.ord(); } protected  GeoHash(); private  GeoHash(double latitude, double longitude, int desiredPrecision); static void main(String[] args); static int getBitsToShift(int b1, int b2); static GeoHash withUnprecisionOfDistanceInMeter(double centerLat, double centerLong, double distanceInMeter); static GeoHash withCharacterPrecision(double latitude, double longitude, int numberOfCharacters); static GeoHash withBitPrecision(double latitude, double longitude, int numberOfBits); static GeoHash fromBinaryString(String binaryString); static GeoHash fromGeohashString(String geohash); static GeoHash fromIntValue(int hashVal); static GeoHash fromLongValue(long hashVal, int significantBits); GeoHash next(int step); GeoHash next(); GeoHash prev(); long ord(); static GeoHash fromOrd(long ord, int significantBits); static long stepsBetween(GeoHash one, GeoHash two); GeoHash[] getAdjacent(); int significantBits(); long longValue(); int intValue(); String toBase32(); boolean within(GeoHash boundingBox); boolean contains(WGS84Point point); WGS84Point getPoint(); WGS84Point getBoundingBoxCenterPoint(); BoundingBox getBoundingBox(); boolean enclosesCircleAroundPoint(WGS84Point point, double radius); GeoHash getNorthernNeighbour(); GeoHash getSouthernNeighbour(); GeoHash getEasternNeighbour(); GeoHash getWesternNeighbour(); @Override String toString(); String toBinaryString(); @Override boolean equals(Object obj); @Override int hashCode(); @Override int compareTo(GeoHash o); static double distFromInMeter(double lat1, double lng1, double lat2, double lng2); static final long FIRST_BIT_FLAGGED; }