Nim bindings for the Geolocation Web API.
The following example only works on the JS target.
import std/strformat
import webgeolocation
proc success(position: GeolocationPosition): void =
let
lat = position.coords.latitude
lon = position.coords.longitude
echo fmt"https://www.openstreetmap.org/#map=18/{lat}/{lon}".cstring
echo fmt"Latitude: {lat}, Longitude: {lon}".cstring
proc error(error: GeolocationPositionError): void =
echo "Unable to retrieve your position: ".cstring & error.message
if isGeolocationAvailable():
geolocation.getCurrentPosition(success, error)
else:
echo "Geolcation API is unavailable!"The demo presented on the MDN page for the Geolocation API
is included in the tests/ directory.
You will need Karax to build it
and Python 3 to execute the demo task.
Run nimble demo. This will build a small Karax application which
you can access at http://localhost:8080.
Build documentation with nim docs