/olc

Convert coordinates between Latitude/Longitude and Open Location Code

Primary LanguageCommon LispGNU General Public License v3.0GPL-3.0

olc

The active repository is at https://codeberg.org/glv/olc

This is a Common Lisp library to convert coordinates between Latitude/Longitude and Open Location Code.

API

In the library, latitude and longitude are represented by real numbers (degrees), positive for northern latitude and eastern longitudes, and negative for southern latitude and western longitudes.

(lat/lon->olc latitude longitude &optional extra-precision) -> string

Return the Open Location Code for the given latitude and longitude. If extra-precision is not nil, an 11 digit code will be returned instead of a 10 digit one.

(olc->lat/lon code &optional center-p) -> list

Return the latitude and longitude for the southwest corner of the given Open Location Code square, or the center of the square if center-p is not nil.

Examples

Load the library:

> (asdf:load-system "olc")
...

Get the Open Locator Code for the Nairobi Youth Sports Organization and Information Centre in Kibera, Nairobi:

> (olc:lat/lon->olc -1.314121 36.798829 t)
"6GCRMQPX+9G4"

Get back the latitude and longitude of the Nairobi Youth Sports Organization and Information Centre in Kibera, Nairobi:

> (olc:olc->lat/lon "6GCRMQPX+9G4" t)
(-1.3141125000000042d0 36.798828125d0)

Tests

The tests require the fiveam library.

(asdf:test-system "olc")