openlocationcode v0.1.0 OpenLocationCode
Open Location Code (OLC) is a geocoding system for identifying an area anywhere on planet Earth. Originally developed in 2014, OLCs are also called "plus codes". Nearby locations have similar codes, and they can be encoded and decoded offline. As blocks are refined to a smaller and smaller area, the number of trailing zeros in a plus code will shrink.
For more information on the OLC specification, check the OLC Wikipedia entry
There are two main functions in this module--encoding and decoding.
Link to this section Summary
Functions
Decodes a code string into an OpenLocationCode.CodeArea struct
Encodes a location into an Open Location Code string
Link to this section Functions
decode(olcstring)
Decodes a code string into an OpenLocationCode.CodeArea struct
Examples
iex> OpenLocationCode.decode("6PH57VP3+PR")
%OpenLocationCode.CodeArea{lat_resolution: 1.25e-4,
long_resolution: 1.25e-4,
south_latitude: 1.2867499999999998,
west_longitude: 103.85449999999999}
encode(latitude, longitude, code_length \\ 10)
Encodes a location into an Open Location Code string.
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 refer to areas smaller than the accuracy of most devices.
Latitude is in signed decimal degrees and will be clipped to the range -90 to 90. Longitude is in signed decimal degrees and will be clipped to the range -180 to 180.
Examples
iex> OpenLocationCode.encode(20.375,2.775, 6)
"7FG49Q00+"
iex> OpenLocationCode.encode(20.3700625,2.7821875)
"7FG49QCJ+2V"