Search documentation of mob

# Mob.Location (mob v0.6.18)

Copy Markdown View Source

Device location (GPS / network).

Requires `:location` permission (request via `Mob.Permissions.request/2`). iOS additionally needs `NSLocationWhenInUseUsageDescription` in `Info.plist`; Android needs `ACCESS_FINE_LOCATION` and/or `ACCESS_COARSE_LOCATION` in `AndroidManifest.xml`. See the permissions guide for the cross-platform table and the "the dialog never appears" failure mode — a missing plist key or manifest entry is the single most common reason this module silently does nothing.

Location updates arrive as:

    handle_info({:location, %{lat: lat, lon: lon, accuracy: acc, altitude: alt}}, socket)
    handle_info({:location, :error, reason}, socket)

Common `reason` atoms:

- `:permission_denied` — user denied `:location` (or revoked it mid-session via Settings). iOS surfaces this through `locationManagerDidChangeAuthorization:`; Android via the permission flow.
- `:unavailable` — the OS can't get a fix right now (`CLLocationManager.didFailWithError`).

iOS: `CLLocationManager`. Android: `FusedLocationProviderClient`.

## Summary

### Types

accuracy()

### Functions

get_once(socket)

Request a single location fix, then stop.

start(socket, opts \\ [])

Start continuous location updates.

stop(socket)

Stop continuous location updates.

## Types

# accuracy()

    @type accuracy() :: :high | :balanced | :low

## Functions

# get_once(socket)

    @spec get_once(Mob.Socket.t()) :: Mob.Socket.t()

Request a single location fix, then stop.

# start(socket, opts \\ [])

    @spec start(
      Mob.Socket.t(),
      keyword()
    ) :: Mob.Socket.t()

Start continuous location updates.

Options:

- `accuracy: :high | :balanced | :low` (default `:balanced`)

Call `stop/1` when done to save battery.

# stop(socket)

    @spec stop(Mob.Socket.t()) :: Mob.Socket.t()

Stop continuous location updates.