GPS
Overview
ExLocation asks the modem's GNSS engine for a position once per second.
It needs the modem firmware running, and a clear view of the sky: go
outside or sit by a window. The first fix can take a few minutes.
Tracker state
ExLocation.state()
:tracking means the GNSS engine is running. :starting means it is
still waiting for the modem.
Satellites in view
ExLocation.satellites()
|> Enum.map(&Map.take(&1, [:system, :sv_id, :status, :elevation, :azimuth]))
Current position
ExLocation.get_position()
{:error, :no_fix_yet} means there is no fix yet; wait and run it again.
Follow the position
Prints each new fix for 60 seconds.
ExLocation.subscribe()
frame = Kino.Frame.new() |> Kino.render()
# 60 rounds; each waits up to 1 second for a message from ExLocation.
for _round <- 1..60 do
receive do
{ExLocation, :position, fix} ->
text = "#{fix.latitude}, #{fix.longitude} (#{length(fix.satellites_used)} satellites)"
Kino.Frame.render(frame, Kino.Markdown.new(text))
{ExLocation, _other, _} ->
:ok
after
1_000 -> :ok
end
end
ExLocation.unsubscribe()