Method: OpenLocationCode.encode

Defined in:
lib/open_location_code.rb

.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.

Parameters:

  • latitude (Float)

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

  • longitude (Float)

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

  • code_length (Integer) (defaults to: nil)

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

Returns:

  • (String)

    Encoded code



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