@@ -19,6 +19,9 @@ public final class OpenLocationCode {
19
19
private static final BigDecimal BD_20 = new BigDecimal (20 );
20
20
private static final BigDecimal BD_90 = new BigDecimal (90 );
21
21
private static final BigDecimal BD_180 = new BigDecimal (180 );
22
+ private static final double LATITUDE_PRECISION_8_DIGITS = computeLatitudePrecision (8 ) / 4 ;
23
+ private static final double LATITUDE_PRECISION_6_DIGITS = computeLatitudePrecision (6 ) / 4 ;
24
+ private static final double LATITUDE_PRECISION_4_DIGITS = computeLatitudePrecision (4 ) / 4 ;
22
25
23
26
private static final char [] ALPHABET = "23456789CFGHJMPQRVWX" .toCharArray ();
24
27
private static final Map <Character , Integer > CHARACTER_TO_INDEX = new HashMap <>();
@@ -309,13 +312,13 @@ public OpenLocationCode shorten(double referenceLatitude, double referenceLongit
309
312
double latitudeDiff = Math .abs (referenceLatitude - codeArea .getCenterLatitude ());
310
313
double longitudeDiff = Math .abs (referenceLongitude - codeArea .getCenterLongitude ());
311
314
312
- if (latitudeDiff < 0.000625 && longitudeDiff < 0.000625 ) {
315
+ if (latitudeDiff < LATITUDE_PRECISION_8_DIGITS && longitudeDiff < LATITUDE_PRECISION_8_DIGITS ) {
313
316
return new OpenLocationCode (code .substring (8 ));
314
317
}
315
- if (latitudeDiff < 0.0125 && longitudeDiff < 0.0125 ) {
318
+ if (latitudeDiff < LATITUDE_PRECISION_6_DIGITS && longitudeDiff < LATITUDE_PRECISION_6_DIGITS ) {
316
319
return new OpenLocationCode (code .substring (6 ));
317
320
}
318
- if (latitudeDiff < 0.25 && longitudeDiff < 0.25 ) {
321
+ if (latitudeDiff < LATITUDE_PRECISION_4_DIGITS && longitudeDiff < LATITUDE_PRECISION_4_DIGITS ) {
319
322
return new OpenLocationCode (code .substring (4 ));
320
323
}
321
324
throw new IllegalArgumentException (
0 commit comments