API Docs

An independent location tracking object.

Create via hs.location.addWatcher(). Call start() to begin receiving updates, and set a callback to handle them.

The callback receives (event, data):

Event Data
"location" a locationTable
"error" an error message string
"authorizationChanged" the new status string ("authorized", "denied", "restricted", "notDetermined")

Example:

const w = hs.location.addWatcher()
w.setCallback((event, data) => {
    if (event === 'location') console.log(data.latitude, data.longitude)
})
w.start()

Properties

identifier

string
The unique identifier assigned to this watcher.

distanceFilter

number
The minimum distance in metres the device must move before a new update is delivered. Defaults to `kCLDistanceFilterNone` (all movements reported).

Methods

start() -> HSLocationWatcher

Starts location updates. The callback must be set first.
start() -> HSLocationWatcher
HSLocationWatcher
self, for chaining
const w = hs.location.addWatcher()
w.setCallback((ev, d) => console.log(ev, d)).start()

stop() -> HSLocationWatcher

Stops location updates.
stop() -> HSLocationWatcher
HSLocationWatcher
self, for chaining
w.stop()

setCallback(fn) -> HSLocationWatcher

Sets the callback function invoked when location events occur.
setCallback(fn) -> HSLocationWatcher
Name Type Description
fn JSValue `function(event, data)` — see type documentation for event names
HSLocationWatcher
self, for chaining
w.setCallback((event, data) => {
    if (event === 'location') console.log(data.latitude, data.longitude)
})

location() -> [AnyHashable: Any]

Returns the most recently received location, or null if none yet.
location() -> [AnyHashable: Any]
[AnyHashable: Any]
a locationTable, or null
const loc = w.location()
if (loc) console.log(`${loc.latitude}, ${loc.longitude}`)