Location
Location and geocoding services
The device's coordinates, plus geocoding, distance and opening a place in Maps. Needs location access: current() asks the first time it runs in the app, and status, isAuthorized and requestAccess() let a script ask first.
Properties
latitudeNumberLatitude
longitudeNumberLongitude
altitudeNumberAltitude
accuracy.horizontalNumberaccuracy.verticalNumberstatusString"authorized", "denied", "restricted" or "notDetermined".
isAuthorizedBooleanTrue when the location can be read.
Methods
.reverseGeocode(locale?)[GeoResult] ›Reverse geocode this coordinate to get address information.
- locale String
.formattedAddress(locale?)StringGet a formatted address string for this coordinate.
- locale String
.distanceTo(other)RootlessDistanceThe distance to another coordinate, as a Distance: d.inKilometers, d.inMeters, d.formatted().
- other Coordinate required
.isWithin(radius, center)BooleanWhether this coordinate is within a radius of another.
- radius Distance | number required
A Distance, or a number of kilometres.
- center Coordinate required
The point to measure from.
.bearingTo(other)NumberBearing in degrees (0-360) to another coordinate.
- other Coordinate required
.openInMaps(label?)Open this coordinate in Apple Maps.
- label String
Location.requestAccess()StringShows the permission sheet. App only.
returns The status afterwards.
Location.current(options?)CoordinateGet the current device location.
- options Any
- accuracy String
"best", "nearest10Meters", "hundredMeters", "kilometer" or "threeKilometers". Coarser is faster and uses less battery.
- accuracy String
Location.at(latitude, longitude)CoordinateA coordinate from latitude and longitude, for distances and bearings without asking the device.
- latitude Number required
- longitude Number required
Examples
Current location & address
const loc = Location.current({accuracy: "100m"});
const address = loc.formattedAddress();
console.log(address);Distance calculation
const home = Location.at(40.7128, -74.0060);
const office = Location.at(40.7589, -73.9851);
const km = home.distanceTo(office);
console.log(`${km.toFixed(1)} km away`);