@Test public void encodeHashToLong() { assertEquals(0x65c0000000000002L, GeoHash.encodeHashToLong(41.842967, -72.727175, 2)); }
static long encodeHashToLong(double latitude, double longitude, int length) { boolean isEven = true; double minLat = -90.0, maxLat = 90; double minLon = -180.0, maxLon = 180.0; long bit = 0x8000000000000000L; long g = 0; long target = 0x8000000000000000L >>> (5 * length); while (bit != target) { if (isEven) { double mid = (minLon + maxLon) / 2; if (longitude >= mid) { g |= bit; minLon = mid; } else maxLon = mid; } else { double mid = (minLat + maxLat) / 2; if (latitude >= mid) { g |= bit; minLat = mid; } else maxLat = mid; } isEven = !isEven; bit >>>= 1; } return g |= length; }
GeoHash { static long encodeHashToLong(double latitude, double longitude, int length) { boolean isEven = true; double minLat = -90.0, maxLat = 90; double minLon = -180.0, maxLon = 180.0; long bit = 0x8000000000000000L; long g = 0; long target = 0x8000000000000000L >>> (5 * length); while (bit != target) { if (isEven) { double mid = (minLon + maxLon) / 2; if (longitude >= mid) { g |= bit; minLon = mid; } else maxLon = mid; } else { double mid = (minLat + maxLat) / 2; if (latitude >= mid) { g |= bit; minLat = mid; } else maxLat = mid; } isEven = !isEven; bit >>>= 1; } return g |= length; } }
GeoHash { static long encodeHashToLong(double latitude, double longitude, int length) { boolean isEven = true; double minLat = -90.0, maxLat = 90; double minLon = -180.0, maxLon = 180.0; long bit = 0x8000000000000000L; long g = 0; long target = 0x8000000000000000L >>> (5 * length); while (bit != target) { if (isEven) { double mid = (minLon + maxLon) / 2; if (longitude >= mid) { g |= bit; minLon = mid; } else maxLon = mid; } else { double mid = (minLat + maxLat) / 2; if (latitude >= mid) { g |= bit; minLat = mid; } else maxLat = mid; } isEven = !isEven; bit >>>= 1; } return g |= length; } private  GeoHash(); }
GeoHash { static long encodeHashToLong(double latitude, double longitude, int length) { boolean isEven = true; double minLat = -90.0, maxLat = 90; double minLon = -180.0, maxLon = 180.0; long bit = 0x8000000000000000L; long g = 0; long target = 0x8000000000000000L >>> (5 * length); while (bit != target) { if (isEven) { double mid = (minLon + maxLon) / 2; if (longitude >= mid) { g |= bit; minLon = mid; } else maxLon = mid; } else { double mid = (minLat + maxLat) / 2; if (latitude >= mid) { g |= bit; minLat = mid; } else maxLat = mid; } isEven = !isEven; bit >>>= 1; } return g |= length; } private  GeoHash(); static String adjacentHash(String hash, Direction direction); static String right(String hash); static String left(String hash); static String top(String hash); static String bottom(String hash); static String adjacentHash(String hash, Direction direction, int steps); static List<String> neighbours(String hash); static String encodeHash(double latitude, double longitude); static String encodeHash(LatLong p, int length); static String encodeHash(LatLong p); static String encodeHash(double latitude, double longitude, int length); static LatLong decodeHash(String geohash); static int hashLengthToCoverBoundingBox(double topLeftLat, double topLeftLon,
            double bottomRightLat, double bottomRightLon); static boolean hashContains(String hash, double lat, double lon); static Coverage coverBoundingBox(double topLeftLat, final double topLeftLon,
            final double bottomRightLat, final double bottomRightLon); static Coverage coverBoundingBoxMaxHashes(double topLeftLat, final double topLeftLon,
            final double bottomRightLat, final double bottomRightLon, int maxHashes); static Coverage coverBoundingBox(double topLeftLat, final double topLeftLon,
            final double bottomRightLat, final double bottomRightLon, final int length); static double heightDegrees(int n); static double widthDegrees(int n); static String gridAsString(String hash, int size, Set<String> highlightThese); static String gridAsString(String hash, int fromRight, int fromBottom, int toRight,
            int toBottom); static String gridAsString(String hash, int fromRight, int fromBottom, int toRight,
            int toBottom, Set<String> highlightThese); }
GeoHash { static long encodeHashToLong(double latitude, double longitude, int length) { boolean isEven = true; double minLat = -90.0, maxLat = 90; double minLon = -180.0, maxLon = 180.0; long bit = 0x8000000000000000L; long g = 0; long target = 0x8000000000000000L >>> (5 * length); while (bit != target) { if (isEven) { double mid = (minLon + maxLon) / 2; if (longitude >= mid) { g |= bit; minLon = mid; } else maxLon = mid; } else { double mid = (minLat + maxLat) / 2; if (latitude >= mid) { g |= bit; minLat = mid; } else maxLat = mid; } isEven = !isEven; bit >>>= 1; } return g |= length; } private  GeoHash(); static String adjacentHash(String hash, Direction direction); static String right(String hash); static String left(String hash); static String top(String hash); static String bottom(String hash); static String adjacentHash(String hash, Direction direction, int steps); static List<String> neighbours(String hash); static String encodeHash(double latitude, double longitude); static String encodeHash(LatLong p, int length); static String encodeHash(LatLong p); static String encodeHash(double latitude, double longitude, int length); static LatLong decodeHash(String geohash); static int hashLengthToCoverBoundingBox(double topLeftLat, double topLeftLon,
            double bottomRightLat, double bottomRightLon); static boolean hashContains(String hash, double lat, double lon); static Coverage coverBoundingBox(double topLeftLat, final double topLeftLon,
            final double bottomRightLat, final double bottomRightLon); static Coverage coverBoundingBoxMaxHashes(double topLeftLat, final double topLeftLon,
            final double bottomRightLat, final double bottomRightLon, int maxHashes); static Coverage coverBoundingBox(double topLeftLat, final double topLeftLon,
            final double bottomRightLat, final double bottomRightLon, final int length); static double heightDegrees(int n); static double widthDegrees(int n); static String gridAsString(String hash, int size, Set<String> highlightThese); static String gridAsString(String hash, int fromRight, int fromBottom, int toRight,
            int toBottom); static String gridAsString(String hash, int fromRight, int fromBottom, int toRight,
            int toBottom, Set<String> highlightThese); static final int MAX_HASH_LENGTH; static final int DEFAULT_MAX_HASHES; }