Module: OpenLocationCode
- Defined in:
- lib/open_location_code.rb,
lib/open_location_code/decoder.rb,
lib/open_location_code/encoder.rb,
lib/open_location_code/version.rb,
lib/open_location_code/code_area.rb
Overview
Example:
# Encode a location, default accuracy:
code = OpenLocationCode.encode(47.365590, 8.524997) # 8FVC9G8F+6X
# Encode a location using one stage of additional refinement:
code = OpenLocationCode.encode(47.365590, 8.524997, 11) # 8FVC9G8F+6XQ
# Decode a full code:
coord = OpenLocationCode.decode(code)
Defined Under Namespace
Classes: CodeArea, Decoder, Encoder
Constant Summary collapse
- SEPARATOR =
A separator used to break the code into two parts to aid memorability
'+'- SEPARATOR_POSITION =
The number of characters to place before the separator.
8- PADDING_CHARACTER =
The character used to pad codes.
'0'- CODE_ALPHABET =
The character set used to encode the values.
'23456789CFGHJMPQRVWX'- ENCODING_BASE =
The base to use to convert numbers to/from.
CODE_ALPHABET.length
- LATITUDE_MAX =
The maximum value for latitude in degrees.
90- LONGITUDE_MAX =
The maximum value for longitude in degrees.
180- PAIR_CODE_LENGTH =
Maxiumum code length using lat/lng pair encoding. The area of such a code is approximately 13x13 meters (at the equator), and should be suitable for identifying buildings. This excludes prefix and separator characters.
10- PAIR_RESOLUTIONS =
The resolution values in degrees for each position in the lat/lng pair encoding. These give the place value of each position, and therefore the dimensions of the resulting area.
[20.0, 1.0, 0.05, 0.0025, 0.000125]
- GRID_COLUMNS =
Number of columns in the grid refinement method.
4- GRID_ROWS =
Number of rows in the grid refinement method.
5- GRID_SIZE_DEGREES =
Size of the initial grid in degrees.
0.000125
- MIN_TRIMMABLE_CODE_LEN =
Minimum length of a code that can be shortened.
6- OLCError =
Error class
Class.new(StandardError)
- VERSION =
Version of lib
"0.1.0"
Class Method Summary collapse
-
.alphabet ⇒ String
OLC alphabet.
-
.decode(code) ⇒ CodeArea
Decodes an Open Location Code into the location coordinates.
-
.encode(latitude, longitude, code_length = nil) ⇒ String
Encode a location into an Open Location Code.
Class Method Details
.alphabet ⇒ String
OLC alphabet.
70 71 72 |
# File 'lib/open_location_code.rb', line 70 def self.alphabet CODE_ALPHABET end |
.decode(code) ⇒ CodeArea
Decodes an Open Location Code into the location coordinates.
105 106 107 |
# File 'lib/open_location_code.rb', line 105 def self.decode(code) Decoder.new(code).process end |
.encode(latitude, longitude, code_length = nil) ⇒ String
Encode a location into an Open Location Code.
Produces a code of the specified length, or the default length if no length
is provided.
The length determines the accuracy of the code. The default length is
10 characters, returning a code of approximately 13.5x13.5 meters. Longer
codes represent smaller areas, but lengths > 14 are sub-centimetre and so
11 or 12 are probably the limit of useful codes.
93 94 95 |
# File 'lib/open_location_code.rb', line 93 def self.encode(latitude, longitude, code_length = nil) Encoder.new(latitude, longitude, code_length || PAIR_CODE_LENGTH).process end |