@@ -39,6 +39,95 @@ limitations under the License.
3939Original C library created by Pieter Geelen. Work on Java version
4040of the mapcode library by Rijn Buve. Initial port by Matthew Lowden.
4141
42+ # Using the Mapcode Library
43+
44+ For a description of what mapcodes are, please visit http://mapcode.com .
45+
46+ This library exposes a ` Mapcode ` class, which represents a full mapcode,
47+ consisting of a code and a territory. You can extract the code and territory
48+ with methods like ` getCode() ` and ` getTerritory() ` . Codes may be retrieved
49+ in a multitude of scripts (or 'alphabets', as they are called in this
50+ library), such as Roman, Greek, Hindi and Arabic.
51+
52+ ` Mapcode ` objects are returned by the ` MapcodeCodec ` with encodes coordinates
53+ to mapcodes and decodes mapcodes to coordinates (codec means coder/decoder).
54+
55+ # Examples
56+
57+ Here's an example to ` decode() ` mapcode within a given territory context.
58+ Note that the territory context (` NLD ` is this case) is only used to
59+ disambiguate the code if needed. If the provided code is an international
60+ code, the context is simply ignored, because no disambiguation is needed.
61+
62+ final Territory territory = Territory.fromString("NLD");
63+ final String mapcode = "49.4V";
64+ try {
65+ final Point p = MapcodeCodec.decode(mapcode, territory);
66+ // p now points at the (lat, lon) for the mapcode.
67+ } catch (final UnknownMapcodeException ignored) {
68+ // The mapcode was not valid.
69+ }
70+
71+ And to ` encode() ` a latitude and longitude into a mapcode you would write:
72+
73+ final List<Mapcode> results = MapcodeCodec.encode(lat, lon);
74+
75+ As you see, the returned result is actually a list of mapcodes. That's
76+ because many locations have multiple mapcodes. The last code in the list
77+ is always the longest code, the international code. This means this method
78+ always returns a result (as for every location on Earth, there is at least
79+ one mapcode).
80+
81+ So, the last code is the international code, but notice that the first code
82+ is not always the shortest, nor does it need to have the "correct"
83+ territory associated to it.
84+
85+ If you want to get the shortest code for a coordinate, you should should
86+ specify a territory and use ` encodeToShortest ` like this:
87+
88+ final Territory territory = Territory.NLD;
89+ final Mapcode mapcode = encodeToShortest(lat, lon, territory);
90+
91+ This makes sure you get the shortest code for a coordinate which has
92+ territory ` NLD ` (or whatever you choose the territory to be).
93+
94+ This method may fail, as the specified coordinate may not lie in the
95+ specified territory. In that case a ` UnknownMapcodeException ` is thrown.
96+
97+ The ` Mapcode ` class offers some additional methods to, for example, get
98+ high-resolution mapcode strings.
99+
100+ // Retrieve an ultra-high precision mapcode.
101+ final String highRez = mapcode.getCode(8);
102+
103+ Or to get full mapcode strings (Unicode), in different scripts (or alphabets):
104+
105+ // Get a Roman version of the mapcode.
106+ final String roman = mapcode.getCodeWithTerritory(Alphabet.ROMAN);
107+
108+ // Get an Arabic version of the mapcode.
109+ final String arabic = mapcode.getCodeWithTerritory(Alphabet.ARABIC);
110+
111+ Note that mapcodes from different scripts can be passed as strings back
112+ to the decoder and they will 'just work'.
113+
114+ There's also a ` Territory ` class, which allows you get territory codes,
115+ given their ISO 3-character code, or their full names (or even some
116+ supported aliases).
117+
118+ final Territory territory = Territory.fromString("France");
119+ // territory is now Territory.FRA.
120+
121+ Finally, there is a ` Point ` utility class, which represents coordinates
122+ with a latitude and longitude. The class offers some simple utility methods
123+ like ` distanceInMeters ` to calculate the distance between two points. Note
124+ that this method is only accurate for pretty short distances, up to, say
125+ a couple of hundred kilometers.
126+
127+ The ` Point ` class is usually easier to use than individual latitude and
128+ longitude paramters and class makes sure it always wraps latitudes to
129+ a range of ` [-90, 90] ` and longitude to ` [-180, 180> ` .
130+
42131# Coding Formatting Style
43132
44133The code formatting style used is the default code formatting style from IntelliJ IDEA (version 14).
0 commit comments