@@ -18,30 +18,25 @@ isValid:
18
18
sequence or not.
19
19
20
20
To be valid, all characters must be from the Open Location Code character
21
- set with at most one separator. If the separator character is present, it
22
- must be after four characters. If the prefix character is present, it must
23
- be the first character.
21
+ set with exactly one separator. There must be an even number of at most
22
+ eight characters before the separator. (Zero characters before the
23
+ separator is valid.)
24
24
25
25
isShort:
26
26
The isShort method takes a single parameter, a string, and returns a
27
27
boolean indicating whether the string is a valid short Open Location Code
28
28
or not.
29
29
30
- A short Open Location Code is a sequence created by removing the first
31
- four or six characters from a full Open Location Code.
32
-
33
- A code must be a possible sub-string of a generated Open Location Code, at
34
- least four and at most seven characters long and not include a separator
35
- character. If the prefix character is present, it must be the first
36
- character.
30
+ A short Open Location Code is a sequence created by removing a even number
31
+ of characters from a full Open Location Code. The resulting code must still
32
+ include the separator character.
37
33
38
34
isFull:
39
35
Determines if a code is a valid full Open Location Code.
40
36
41
37
Not all possible combinations of Open Location Code characters decode to
42
38
valid latitude and longitude values. This checks that a code is valid and
43
- also that the latitude and longitude values are legal. If the prefix
44
- character is present, it must be the first character. If the separator
39
+ also that the latitude and longitude values are legal. If the separator
45
40
character is present, it must be after four characters.
46
41
47
42
encode:
@@ -55,43 +50,21 @@ decode:
55
50
returns an object with the lower and upper latitude and longitude pairs,
56
51
the center latitude and longitude, and the length of the original code.
57
52
58
- shortenBy4:
59
- Passed a valid full 10 or 11 character Open Location Code and a latitude
60
- and longitude, this tries to remove the first four characters. This will
61
- only succeed if both the latitude and longitude are less than 0.25
62
- degrees from the code center. (Up to 0.5 degrees difference would work,
63
- the requirement for 0.25 degrees represents a safety margin for cases
64
- where the coordinates have come from a geocoding system and where the
65
- center of large entities, such as cities, is subject to debate.)
66
-
67
- If not possible, the original code is returned. If trimming is possible,
68
- the first four characters are removed and the subsequent characters are
69
- returned with the prefix added.
70
-
71
- shortenBy6:
72
- Passed a valid full 10 or 11 character Open Location Code and a latitude
73
- and longitude, this tries to remove the first six characters. This will
74
- only succeed if both the latitude and longitude are less than 0.0125
75
- degrees from the code center. (Up to 0.025 degrees difference would
76
- work, the requirement for 0.0125 degrees represents a safety margin for
77
- cases where the coordinates have come from a geocoding system and where
78
- the center of large entities, such as cities, is subject to debate.)
79
-
80
- If not possible, the original code is returned. If trimming is possible,
81
- the first six characters are removed and the subsequent characters are
82
- returned with the prefix added.
53
+ shorten:
54
+ Passed a valid full Open Location Code and a latitude and longitude this
55
+ removes as many digits as possible (up to a maximum of eight) such that
56
+ the resulting code is the closest matching code to the passed location.
57
+ A safety factor may be included.
58
+
59
+ If the code cannot be shortened, the original full code should be
60
+ returned.
61
+
62
+ Since the only really useful shortenings are removing the first four or
63
+ six characters, this method may be replaced with methods such as
64
+ shortenBy4 or shortenBy6.
83
65
84
66
recoverNearest:
85
- This method is passed a valid short Open Location Code (of four to seven
86
- characters) and a latitude and longitude, and returns the nearest
87
- matching full Open Location Code to the specified location.
88
-
89
- The number of characters that will be prepended to the short code, where S
90
- is the supplied short code and R are the computed characters, are:
91
- SSSS -> RRRR.RRSSSS
92
- SSSSS -> RRRR.RRSSSSS
93
- SSSSSS -> RRRR.SSSSSS
94
- SSSSSSS -> RRRR.SSSSSSS
95
- Note that short codes with an odd number of characters will have their
96
- last character decoded using the grid refinement algorithm.
67
+ This method is passed a valid short Open Location Code and a latitude and
68
+ longitude, and returns the nearest matching full Open Location Code to
69
+ the specified location.
97
70
0 commit comments