use web/geolocation

Dependencies: web/geolocation

https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API

geolocation.can? ( → t )

Returns true if the user’s device has a GPS unit, that is, whether getting the geolocation is even possible. Note that this will strill return true if the user denied permission to access their location.

geolocation.getpos ( → p )

Returns a GeolocationPosition object with the user’s position, or throws an error if the user denied permission or GPS is not available.

Example, which prints your location:

use web/geolocation

geolocation.can? iff do
    geolocation.getpos
    .coords
    dup
    $ "Your position: " echo
    .longitude dup 0 > iff $ "degrees N" else $ "degrees S" ++ echo
    .latitude dup 0 > iff $ "degrees E" else $ "degrees W" ++ echo
end
else do
    $ "Position not available." echo
end

back to index

docs@04547c7