module OpenLocationCode

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)

Constants

CODE_ALPHABET

The character set used to encode the values.

ENCODING_BASE

The base to use to convert numbers to/from.

GRID_COLUMNS

Number of columns in the grid refinement method.

GRID_ROWS

Number of rows in the grid refinement method.

GRID_SIZE_DEGREES

Size of the initial grid in degrees.

LATITUDE_MAX

The maximum value for latitude in degrees.

LONGITUDE_MAX

The maximum value for longitude in degrees.

MIN_TRIMMABLE_CODE_LEN

Minimum length of a code that can be shortened.

OLCError

Error class

PADDING_CHARACTER

The character used to pad codes.

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.

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.

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.

VERSION

Version of lib

Public Class Methods

alphabet() click to toggle source

OLC alphabet. @return [String]

# File lib/open_location_code.rb, line 70
def self.alphabet
  CODE_ALPHABET
end
decode(code) click to toggle source
Decodes an Open Location Code into the location coordinates.

@param [String] code

The Open Location Code to decode.

@return [CodeArea]

An object that provides the latitude and longitude of two of the
corners of the area, the center, and the length of the original code.
# File lib/open_location_code.rb, line 105
def self.decode(code)
  Decoder.new(code).process
end
encode(latitude, longitude, code_length = nil) click to toggle source
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.

@param [Float] latitude

A latitude in signed decimal degrees. Will be clipped to the range -90 to 90.

@param [Float] longitude

A longitude in signed decimal degrees. Will be normalised to the range -180 to 180.

@param [Integer] code_length

The number of significant digits in the output code, not including any separator characters.

@return [String]

Encoded code
# 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