Determine the machine's location and useful information about that location
This module provides functions for getting current location information and tracking location changes. It expands on the earlier version of the module by adding the ability to create independent locationObjects which can enable/disable location tracking independent of other uses of Location Services by Hammerspoon, adds region monitoring for exit and entry, and adds the retrieval of geocoding information through the hs.location.geocoder
submodule.
This module is backwards compatible with its predecessor with the following changes:
hs.location.services_enabled
. While the earlier function is included for backwards compatibility, it will display a deprecation warning to the console the first time it is invoked and may go away completely in the future.The following labels are used to describe tables which are used by functions and methods as parameters or return values in this module and in hs.location.geocoder
. These tables are described as follows:
locationTable
- a table specifying location coordinates containing one or more of the following key-value pairs:
latitude
- a number specifying the latitude in degrees. Positive values indicate latitudes north of the equator. Negative values indicate latitudes south of the equator. When not specified in a table being used as an argument, this defaults to 0.0.longitude
- a number specifying the longitude in degrees. Measurements are relative to the zero meridian, with positive values extending east of the meridian and negative values extending west of the meridian. When not specified in a table being used as an argument, this defaults to 0.0.altitude
- a number indicating altitude above (positive) or below (negative) sea-level. When not specified in a table being used as an argument, this defaults to 0.0.horizontalAccuracy
- a number specifying the radius of uncertainty for the location, measured in meters. If negative, the latitude
and longitude
keys are invalid and should not be trusted. When not specified in a table being used as an argument, this defaults to 0.0.verticalAccuracy
- a number specifying the accuracy of the altitude value in meters. If negative, the altitude
key is invalid and should not be trusted. When not specified in a table being used as an argument, this defaults to -1.0.course
- a number specifying the direction in which the device is traveling. If this value is negative, then the value is invalid and should not be trusted. On current Macintosh models, this will almost always be a negative number. When not specified in a table being used as an argument, this defaults to -1.0.speed
- a number specifying the instantaneous speed of the device in meters per second. If this value is negative, then the value is invalid and should not be trusted. On current Macintosh models, this will almost always be a negative number. When not specified in a table being used as an argument, this defaults to -1.0.timestamp
- a number specifying the time at which this location was determined. This number is the number of seconds since January 1, 1970 at midnight, GMT, and is a floating point number, so you should use math.floor
on this number before using it as an argument to Lua's os.date
function. When not specified in a table being used as an argument, this defaults to the current time.regionTable
- a table specifying a circular region containing one or more of the following key-value pairs:
identifier
- a string for use in identifying the region. When not specified in a table being used as an argument, a new value is generated with hs.host.uuid
.latitude
- a number specifying the latitude in degrees. Positive values indicate latitudes north of the equator. Negative values indicate latitudes south of the equator. When not specified in a table being used as an argument, this defaults to 0.0.longitude
- a number specifying the latitude in degrees. Positive values indicate latitudes north of the equator. Negative values indicate latitudes south of the equator. When not specified in a table being used as an argument, this defaults to 0.0.radius
- a number specifying the radius (measured in meters) that defines the region’s outer boundary. When not specified in a table being used as an argument, this defaults to 0.0.notifyOnEntry
- a boolean specifying whether or not a callback with the "didEnterRegion" message should be generated when the machine enters the region. When not specified in a table being used as an argument, this defaults to true.notifyOnExit
- a boolean specifying whether or not a callback with the "didExitRegion" message should be generated when the machine exits the region. When not specified in a table being used as an argument, this defaults to true.Signature | hs.location.distance(from, to) -> meters |
---|---|
Type | Function |
Description | Measures the distance between two points of latitude and longitude |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/location/liblocation.m line 245 |
Signature | hs.location.dstOffset() -> number |
---|---|
Type | Function |
Description | Returns a number giving the current daylight savings time offset |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/location/liblocation.m line 307 |
Signature | hs.location.get() -> locationTable or nil |
---|---|
Type | Function |
Description | Returns a table representing the current location |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/location/liblocation.m line 282 |
Signature | hs.location.register(tag, fn[, distance]) |
---|---|
Type | Function |
Description | Registers a callback function to be called when the system location is updated |
Parameters |
|
Returns |
|
Source | extensions/location/location.lua line 139 |
Signature | hs.location.servicesEnabled() -> bool |
---|---|
Type | Function |
Description | Gets the state of OS X Location Services |
Parameters |
|
Returns |
|
Source | extensions/location/liblocation.m line 192 |
Signature | hs.location.start() -> boolean |
---|---|
Type | Function |
Description | Begins location tracking using OS X's Location Services so that registered callback functions can be invoked as the computer location changes. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/location/location.lua line 179 |
Signature | hs.location.stop() |
---|---|
Type | Function |
Description | Stops location tracking. Registered callback functions will cease to receive notification of location changes. |
Parameters |
|
Returns |
|
Source | extensions/location/location.lua line 201 |
Signature | hs.location.sunrise(latitude, longitude, offset[, date]) -> number or string |
---|---|
Type | Function |
Description | Returns the time of official sunrise for the supplied location |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/location/liblocation.m line 503 |
Signature | hs.location.sunset(latitude, longitude, offset[, date]) -> number or string |
---|---|
Type | Function |
Description | Returns the time of official sunset for the supplied location |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/location/liblocation.m line 526 |
Signature | hs.location.unregister(tag) |
---|---|
Type | Function |
Description | Unregisters a callback |
Parameters |
|
Returns |
|
Source | extensions/location/location.lua line 166 |
Signature | hs.location.new() -> locationObject |
---|---|
Type | Constructor |
Description | Create a new location object which can receive callbacks independent of other Hammerspoon use of Location Services. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/location/location.lua line 221 |
Signature | hs.location:addMonitoredRegion(regionTable) -> locationObject | nil |
---|---|
Type | Method |
Description | Adds a region to be monitored by Location Services |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/location/location.lua line 358 |
Signature | hs.location:callback(fn) -> locationObject |
---|---|
Type | Method |
Description | Sets or removes the callback function for this locationObject |
Parameters |
|
Returns |
|
Source | extensions/location/location.lua line 461 |
Signature | hs.location:currentRegion() -> identifier | nil |
---|---|
Type | Method |
Description | Returns the string identifier for the current region |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/location/location.lua line 436 |
Signature | hs.location:distanceFrom(locationTable) -> distance | nil |
---|---|
Type | Method |
Description | Enable callbacks for location changes/refinements for this locationObject |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/location/location.lua line 300 |
Signature | hs.location:location() -> locationTable | nil |
---|---|
Type | Method |
Description | Returns the current location |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/location/location.lua line 495 |
Signature | hs.location:monitoredRegions() -> table | nil |
---|---|
Type | Method |
Description | Returns a table containing the regionTables for the regions currently being monitored for this locationObject |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/location/location.lua line 321 |
Signature | hs.location:removeMonitoredRegion(identifier) -> locationObject | false | nil |
---|---|
Type | Method |
Description | Removes a monitored region from Location Services |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/location/location.lua line 406 |
Signature | hs.location:startTracking() -> locationObject |
---|---|
Type | Method |
Description | Enable callbacks for location changes/refinements for this locationObject |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/location/location.lua line 260 |
Signature | hs.location:stopTracking() -> locationObject |
---|---|
Type | Method |
Description | Disable callbacks for location changes/refinements for this locationObject |
Parameters |
|
Returns |
|
Source | extensions/location/location.lua line 281 |