No description
Find a file
2023-04-12 20:43:22 -07:00
src Initial commit 2023-04-11 20:39:03 -07:00
tests Initial commit 2023-04-11 20:39:03 -07:00
.gitignore Chore: Update gitignore. 2023-04-11 20:55:22 -07:00
LICENSE Initial commit 2023-04-11 20:28:15 -07:00
README.md Fix: Be explicit about Python 3 requirements 2023-04-12 20:43:22 -07:00
webgeolocation.nimble Chore: Update gitignore. 2023-04-11 20:55:22 -07:00

Geolocation API

Nim bindings for the Geolocation Web API.

Basic usage

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!"

Demo

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.

Instructions

Run nimble demo. This will build a small Karax application which you can access at http://localhost:8080.

Docs

Build documentation with nim docs