@Test public void testIssue1() { double lat = 40.390943; double lon = -75.9375; GeoHash hash = GeoHash.withCharacterPrecision(lat, lon, 12); String base32 = "dr4jb0bn2180"; GeoHash fromRef = GeoHash.fromGeohashString(base32); assertEquals(hash, fromRef); assertEquals(base32, hash.toBase32()); assertEquals(base32, fromRef.toBase32()); hash = GeoHash.withCharacterPrecision(lat, lon, 10); assertEquals("dr4jb0bn21", hash.toBase32()); }
private void assertEncodingWithCharacterPrecision( WGS84Point point, int numberOfCharacters, String stringValue) { GeoHash hash = GeoHash.withCharacterPrecision( point.getLatitude(), point.getLongitude(), numberOfCharacters); assertEquals(stringValue, hash.toBase32()); }
@Test public void testToLongAndBack() { double lat = 40.390943; double lon = -75.9375; GeoHash hash = GeoHash.withCharacterPrecision(lat, lon, 10); long lv = hash.longValue(); assertEquals(lv + (1 << (64 - hash.significantBits())), hash.next().longValue()); GeoHash hashFromLong = GeoHash.fromLongValue(lv, hash.significantBits()); assertEquals("dr4jb0bn21", hashFromLong.toBase32()); assertEquals(hash, hashFromLong); }
@Test public void testKnownNeighbouringHashes() { GeoHash h1 = GeoHash.fromGeohashString("u1pb"); assertEquals("u0zz", h1.getSouthernNeighbour().toBase32()); assertEquals("u1pc", h1.getNorthernNeighbour().toBase32()); assertEquals("u300", h1.getEasternNeighbour().toBase32()); assertEquals("u302", h1.getEasternNeighbour().getEasternNeighbour().toBase32()); assertEquals("u1p8", h1.getWesternNeighbour().toBase32()); assertEquals("sp2j", GeoHash.withCharacterPrecision(41.7, 0.08, 4).toBase32()); }
private void checkMovingInCircle(double latitude, double longitude) { GeoHash start; GeoHash end; start = GeoHash.withCharacterPrecision(latitude, longitude, 12); end = start.getEasternNeighbour(); end = end.getSouthernNeighbour(); end = end.getWesternNeighbour(); end = end.getNorthernNeighbour(); assertEquals(start, end); assertEquals(start.getBoundingBox(), end.getBoundingBox()); }