https://github.com/haskell-miso/miso-geolocation
🍜 📍 Geolocation API example with miso
https://github.com/haskell-miso/miso-geolocation
geolocation geolocation-api haskell miso
Last synced: 10 months ago
JSON representation
🍜 📍 Geolocation API example with miso
- Host: GitHub
- URL: https://github.com/haskell-miso/miso-geolocation
- Owner: haskell-miso
- License: bsd-3-clause
- Created: 2025-09-10T23:53:00.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2025-09-11T00:40:56.000Z (11 months ago)
- Last Synced: 2025-09-11T03:05:09.541Z (11 months ago)
- Topics: geolocation, geolocation-api, haskell, miso
- Language: Haskell
- Homepage: https://geolocation.haskell-miso.org/
- Size: 18.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
:ramen: 📍 miso-geolocation
====================
A [Geolocation API](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API) example. See live [here](https://geolocation.haskell-miso.org).
> [!TIP]
> This requires installing [nix](https://nixos.org) with [Nix Flakes](https://wiki.nixos.org/wiki/Flakes) enabled.
> Although not required, we recommend using [miso's binary cache](https://github.com/dmjio/miso?tab=readme-ov-file#binary-cache).
### Example
```haskell
-----------------------------------------------------------------------------
data Action
= GetLocation
| ErrorLocation GeolocationError
| SetLocation Geolocation
deriving (Show, Eq)
-----------------------------------------------------------------------------
#ifdef WASM
foreign export javascript "hs_start" main :: IO ()
#endif
-----------------------------------------------------------------------------
main :: IO ()
main = run $ startApp app
-----------------------------------------------------------------------------
type Model = Maybe Geolocation
-----------------------------------------------------------------------------
app :: App Model Action
app = (component Nothing updateModel viewModel)
#ifndef WASM
{ styles =
[ Href "assets/style.css"
]
}
#endif
-----------------------------------------------------------------------------
updateModel :: Action -> Transition Model Action
updateModel = \case
GetLocation -> do
geolocation SetLocation ErrorLocation
SetLocation location -> do
this ?= location
ErrorLocation (GeolocationError _ err) ->
io_ (consoleError err)
```
### Development
Call `nix develop` to enter a shell with [GHC 9.12.2](https://haskell.org/ghc)
```bash
$ nix develop --experimental-features nix-command --extra-experimental-features flakes
```
Once in the shell, you can call `cabal run` to start the development server and view the application at http://localhost:8080
### Build (Web Assembly)
```bash
$ nix develop .#wasm --command bash -c "make"
```
### Build (JavaScript)
```bash
$ nix develop .#ghcjs --command bash -c "build"
```
### Serve
To host the built application you can call `serve`
```bash
$ nix develop .#wasm --command bash -c "serve"
```
### Clean
```bash
$ nix develop .#wasm --command bash -c "make clean"
```
This comes with a GitHub action that builds and auto hosts the example.