Locate the Worker
In case if you don't need a continuous tracking session and just need a one time current location of the worker you can use the Locate API in HyperTrack Mobile SDK API.
locate()
is an asyncronous SDK method that returns you a callback with a location value or a list of outages (the description of why the SDK was unable to get the location, e.g. the permissions were disabled on device).
Here are the examples of usage:
HyperTrack.locate { locateResult in
switch(locateResult) {
case let .success(location):
...
case let .failure(errors):
...
}
}
HyperTrack.locate { locateResult ->
when (locateResult) {
is LocateResult.Success -> {
val location = locateResult.location
...
}
is LocateResult.Failure -> {
val errors = locateResult.errors
...
}
}
}
HyperTrack.locate().then((locateResult) => {
if (locateResult.type === 'success') {
const location = locateResult.location;
...
} else {
const errors = locateResult.errors;
...
}
});
HyperTrack.locate().then((locateResult) {
if (locateResult is Success) {
final location = locateResult.location;
...
} else {
final errors = locateResult.errors;
...
}
});
HyperTrack.locate().then((locateResult) => {
if (locateResult.type === 'success') {
const location = locateResult.location;
...
} else {
const errors = locateResult.errors;
...
}
});
You can check the detailed method spec for you platform in the according API reference: iOS, Android, React Native and Expo, Flutter, Ionic Capacitor, Cordova
Note
There is another SDK method that is easy to confuse:
HyperTrack.location
/HyperTrack.getLocation()
. It's difference from Locate API is that it's synchronous and returns only the current location known to SDK (if there is any), but doesn't ask for update if it doesn't have one. So for example if the SDK is not tracking,locate()
will initiate a new tracking session and wait for a location, andgetLocation()
will just return an error (because the SDK doesn't have a location at that moment).
Updated about 2 months ago