|
| 1 | +# Open Location Code Reference API |
| 2 | + |
| 3 | +## Version History |
| 4 | + |
| 5 | +- Version 1.0.0 / 2014-10-27 / [Doug Rinckes](https://github.com/drinckes), Google / Philipp Bunge, Google |
| 6 | + - Initial public release |
| 7 | + |
| 8 | +## Public methods |
| 9 | + |
| 10 | +The following public methods should be provided by any Open Location Code implementation, subject to minor changes caused by language conventions. |
| 11 | + |
| 12 | +Note that any method that returns an Open Location Code should return upper case characters. |
| 13 | + |
| 14 | +Methods that accept Open Location Codes as parameters should be case insensitive. |
| 15 | + |
| 16 | +### `isValid` |
| 17 | + |
| 18 | +The `isValid` method takes a single parameter, a string, and returns a boolean indicating whether the string is a valid Open Location Code sequence or not. |
| 19 | + |
| 20 | +To be valid, all characters must be from the Open Location Code character set with exactly one separator. |
| 21 | +There must be an even number of at most eight characters before the separator. |
| 22 | +(Zero characters before the separator is valid.) |
| 23 | + |
| 24 | +### `isShort` |
| 25 | + |
| 26 | +The `isShort` method takes a single parameter, a string, and returns a boolean indicating whether the string is a valid short Open Location Code or not. |
| 27 | + |
| 28 | +A short Open Location Code is a sequence created by removing an even number of characters from a full Open Location Code. |
| 29 | +The resulting code must still include the separator character. |
| 30 | + |
| 31 | +### `isFull` |
| 32 | + |
| 33 | +Determines if a code is a valid full Open Location Code. |
| 34 | + |
| 35 | +Not all possible combinations of Open Location Code characters decode to valid latitude and longitude values. |
| 36 | +This checks that a code is valid and also that the latitude and longitude values are legal. |
| 37 | +Full codes must include the separator character and it must be after eight characters. |
| 38 | + |
| 39 | +### `encode` |
| 40 | + |
| 41 | +Encode a location into an Open Location Code. |
| 42 | +This takes a latitude and longitude and an optional length. |
| 43 | +If the length is not specified, a code with 10 digits and an additional separator character will be generated. |
| 44 | + |
| 45 | +### `decode` |
| 46 | + |
| 47 | +Decodes an Open Location Code into the location coordinates. This method takes a string. |
| 48 | +If the string is a valid full Open Location Code, it returns an object with the lower and upper latitude and longitude pairs, the center latitude and longitude, and the length of the original code. |
| 49 | + |
| 50 | +### `shorten` |
| 51 | + |
| 52 | +Passed a valid full Open Location Code and a latitude and longitude this removes as many digits as possible (up to a maximum of six) such that the resulting code is the closest matching code to the passed location. |
| 53 | +A safety factor may be included. |
| 54 | + |
| 55 | +If the code cannot be shortened, the original full code should be returned. |
| 56 | + |
| 57 | +Since the only really useful shortenings are removing the first four or six characters, this method may be replaced with methods such as `shortenBy4` or `shortenBy6`. |
| 58 | + |
| 59 | +### `recoverNearest` |
| 60 | + |
| 61 | +This method is passed a valid short Open Location Code and a latitude and longitude, and returns the nearest matching full Open Location Code to the specified location. |
| 62 | + |
0 commit comments