1 #ifndef OLC_OPENLOCATIONCODE_H_
2 #define OLC_OPENLOCATIONCODE_H_
6 #define OLC_VERSION_MAJOR 1
7 #define OLC_VERSION_MINOR 0
8 #define OLC_VERSION_PATCH 0
10 // OLC version number: 2.3.4 => 2003004
11 // Useful for checking against a particular version or above:
13 // #if OLC_VERSION_NUM < OLC_MAKE_VERSION_NUM(1, 0, 2)
14 // #error UNSUPPORTED OLC VERSION
16 #define OLC_MAKE_VERSION_NUM(major, minor, patch) \
17 ((major * 1000 + minor) * 1000 + patch)
19 // OLC version string: 2.3.4 => "2.3.4"
20 #define OLC_MAKE_VERSION_STR_IMPL(major, minor, patch) \
21 (#major "." #minor "." #patch)
22 #define OLC_MAKE_VERSION_STR(major, minor, patch) \
23 OLC_MAKE_VERSION_STR_IMPL(major, minor, patch)
25 // Current version, as a number and a string
26 #define OLC_VERSION_NUM \
27 OLC_MAKE_VERSION_NUM(OLC_VERSION_MAJOR, OLC_VERSION_MINOR, OLC_VERSION_PATCH)
28 #define OLC_VERSION_STR \
29 OLC_MAKE_VERSION_STR(OLC_VERSION_MAJOR, OLC_VERSION_MINOR, OLC_VERSION_PATCH)
31 // A pair of doubles representing latitude / longitude
32 typedef struct OLC_LatLon
{
37 // An area defined by two corners (lo and hi) and a code length
38 typedef struct OLC_CodeArea
{
44 // Get the center coordinates for an area
45 void OLC_GetCenter(const OLC_CodeArea
* area
, OLC_LatLon
* center
);
47 // Get the effective length for a code
48 size_t OLC_CodeLength(const char* code
, size_t size
);
50 // Check for the three obviously-named conditions
51 int OLC_IsValid(const char* code
, size_t size
);
52 int OLC_IsShort(const char* code
, size_t size
);
53 int OLC_IsFull(const char* code
, size_t size
);
55 // Encode location with given code length (indicates precision) into an OLC
56 // Return the string length of the code
57 int OLC_Encode(const OLC_LatLon
* location
, size_t code_length
, char* code
,
60 // Encode location with default code length into an OLC
61 // Return the string length of the code
62 int OLC_EncodeDefault(const OLC_LatLon
* location
, char* code
, int maxlen
);
64 // Decode OLC into the original location
65 int OLC_Decode(const char* code
, size_t size
, OLC_CodeArea
* decoded
);
67 // Compute a (shorter) OLC for a given code and a reference location
68 int OLC_Shorten(const char* code
, size_t size
, const OLC_LatLon
* reference
,
69 char* buf
, int maxlen
);
71 // Given shorter OLC and reference location, compute original (full length) OLC
72 int OLC_RecoverNearest(const char* short_code
, size_t size
,
73 const OLC_LatLon
* reference
, char* code
, int maxlen
);