19
19
/**
20
20
* Convert locations to and from convenient short codes.
21
21
*
22
- * <p> Open Location Codes are short, ~10 character codes that can be used instead of street
22
+ * Open Location Codes are short, ~10 character codes that can be used instead of street
23
23
* addresses. The codes can be generated and decoded offline, and use a reduced character set that
24
24
* minimises the chance of codes including words.
25
25
*
26
- * <p>This provides both an object and static methods.
26
+ * This provides both object and static methods.
27
+ *
28
+ * Create an object with:
29
+ * OpenLocationCode code = new OpenLocationCode("7JVW52GR+2V");
30
+ * OpenLocationCode code = new OpenLocationCode("52GR+2V");
31
+ * OpenLocationCode code = new OpenLocationCode(27.175063, 78.042188);
32
+ * OpenLocationCode code = new OpenLocationCode(27.175063, 78.042188, 11);
33
+ *
34
+ * Once you have a code object, you can apply the other methods to it, such as to shorten:
35
+ * code.shorten(27.176, 78.05)
36
+ *
37
+ * Recover the nearest match (if the code was a short code):
38
+ * code.recover(27.176, 78.05)
39
+ *
40
+ * Or decode a code into it's coordinates, returning a CodeArea object.
41
+ * code.decode()
42
+ *
43
+ * @author Jiri Semecky
44
+ * @author Doug Rinckes
27
45
*/
28
46
public final class OpenLocationCode {
29
47
@@ -132,6 +150,7 @@ public double getEastLongitude() {
132
150
* Creates Open Location Code object for the provided code.
133
151
* @param code A valid OLC code. Can be a full code or a shortened code.
134
152
* @throws IlegalArgumentException when the passed code is not valid.
153
+ * @constructor
135
154
*/
136
155
public OpenLocationCode (String code ) {
137
156
if (!isValidCode (code .toUpperCase ())) {
@@ -147,6 +166,7 @@ public OpenLocationCode(String code) {
147
166
* @param longitude The longitude in decimal degrees.
148
167
* @param codeLength The desired number of digits in the code.
149
168
* @throws IllegalArgumentException if the code length is not valid.
169
+ * @constructor
150
170
*/
151
171
public OpenLocationCode (double latitude , double longitude , int codeLength )
152
172
throws IllegalArgumentException {
@@ -215,18 +235,28 @@ public OpenLocationCode(double latitude, double longitude, int codeLength)
215
235
this .code = codeBuilder .toString ();
216
236
}
217
237
218
- /** Creates Open Location Code with code length 10 from the provided latitude, longitude. */
238
+ /**
239
+ * Creates Open Location Code with the default precision length.
240
+ * @param latitude The latitude in decimal degrees.
241
+ * @param longitude The longitude in decimal degrees.
242
+ * @constructor
243
+ */
219
244
public OpenLocationCode (double latitude , double longitude ) {
220
245
this (latitude , longitude , CODE_PRECISION_NORMAL );
221
246
}
222
247
248
+ /**
249
+ * Returns the string representation of the code.
250
+ */
223
251
public String getCode () {
224
252
return code ;
225
253
}
226
254
227
255
/**
228
256
* Encodes latitude/longitude into 10 digit Open Location Code. This method is equivalent to
229
257
* creating the OpenLocationCode object and getting the code from it.
258
+ * @param latitude The latitude in decimal degrees.
259
+ * @param longitude The longitude in decimal degrees.
230
260
*/
231
261
public static String encode (double latitude , double longitude ) {
232
262
return new OpenLocationCode (latitude , longitude ).getCode ();
@@ -235,6 +265,8 @@ public static String encode(double latitude, double longitude) {
235
265
/**
236
266
* Encodes latitude/longitude into Open Location Code of the provided length. This method is
237
267
* equivalent to creating the OpenLocationCode object and getting the code from it.
268
+ * @param latitude The latitude in decimal degrees.
269
+ * @param longitude The longitude in decimal degrees.
238
270
*/
239
271
public static String encode (double latitude , double longitude , int codeLength ) {
240
272
return new OpenLocationCode (latitude , longitude , codeLength ).getCode ();
0 commit comments