예제 #1
0
 private void assertEncodingWithCharacterPrecision(
     WGS84Point point, int numberOfCharacters, String stringValue) {
   GeoHash hash =
       GeoHash.withCharacterPrecision(
           point.getLatitude(), point.getLongitude(), numberOfCharacters);
   assertEquals(stringValue, hash.toBase32());
 }
예제 #2
0
  @Test
  public void testByCharacterPrecision() {
    assertEncodingWithCharacterPrecision(new WGS84Point(20, 31), 12, "sew1c2vs2q5r");
    assertEncodingWithCharacterPrecision(new WGS84Point(-20, 31), 12, "ksqn1rje83g2");
    assertEncodingWithCharacterPrecision(
        new WGS84Point(-20.783236276, 31.9867127312312), 12, "ksq9zbs0b7vw");

    WGS84Point point = new WGS84Point(-76.5110040642321, 39.0247389581054);
    String fullStringValue = "hf7u8p8gn747";
    for (int characters = 12; characters > 1; characters--) {
      assertEncodingWithCharacterPrecision(
          point, characters, fullStringValue.substring(0, characters));
    }

    assertEncodingWithCharacterPrecision(
        new WGS84Point(39.0247389581054, -76.5110040642321), 12, "dqcw4bnrs6s7");

    String geoHashString =
        GeoHash.geoHashStringWithCharacterPrecision(point.getLatitude(), point.getLongitude(), 12);
    assertEquals(fullStringValue, geoHashString);
  }