Skip to content

Nim bindings for the Geolocation Web API

License

Notifications You must be signed in to change notification settings

maleyva1/webgeoloaction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Nim bindings for the Geolocation Web API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published