Links

Background Location

You'll need to import the javascript file in your website before starting from this link.
To retrieve device location even when app is in background state
Plain JS
ES 6+
//to start recieving location updates
window.WTN.backgroundLocation.start({
callback,
apiUrl,
timeout,
data,
backgroundIndicator : false,
pauseAutomatically : true,
distanceFilter : 0.0,
desiredAccuracy : "best",
activityType : "other",
})
//to stop recieving location updates
window.WTN.backgroundLocation.stop()
import { start, stop } from "webtonative/BackgroundLocation"
//to start recieving location updates
start({
callback,
apiUrl,
timeout,
data,
backgroundIndicator : false,
pauseAutomatically : true,
distanceFilter : 0.0,
desiredAccuracy : "best",
activityType : "other",
})
//to stop recieving location updates
stop()

call the method with following data

callback: (Optional if apiUrl is provided) a javascript function which we will call to send you location updates
apiUrl: (Optional if callback is provided) a api which will call using POST method to send you location update
data: (Optional) extra data to send along with location update which calling your callback or apiUrl. it can be useful as you can additional data which can be used to identify your user. alternatively you can use query parameter.
backgroundIndicator: (Optional, Default false, iOS Only) Modifies status bar on iOS to indicate that app is using location services when app is backgrounded
pauseAutomatically: (Optional, Default true, iOS Only) Setting this property to true causes the location manager to pause updates (and powers down the appropriate hardware) at times when the location data is unlikely to change. Allowing the location manager to pause updates can improve battery life on the target device without sacrificing location data.
distanceFilter: (Optional, in meters Default 0.0) The minimum distance (measured in meters) a device must move horizontally before an update event is generated.
desiredAccuracy: (Optional, Default best, iOS Only) The accuracy of the location data that your app wants to receive.
  • best: (Default) the best accuracy possible
  • bestForNavigation: The highest possible accuracy that uses additional sensor data to facilitate navigation apps.
  • tenMeters: Accurate to within ten meters of the desired target.
  • hundredMeters: Accurate to within one hundred meters.
  • kilometer: Accurate to the nearest kilometer.
  • threeKilometers: Accurate to the nearest three kilometers.
activityType: (optional, Default other, iOS Only) The type of user activity associated with the location updates.
  • other: (Default) The location manager is being used for an unknown activity.
  • automotiveNavigation: The location manager is being used specifically during vehicular navigation to track location changes to the automobile.
  • otherNavigation: The location manager is being used to track movements for other types of vehicular navigation that are not automobile related.
  • fitness: The location manager is being used to track fitness activities such as walking, running, cycling, and so on.
  • airborne: The location manager is being used specifically during airborne activities.
Note: Location update will be sent to callback and/or apiUrl when app is in foreground. when app is in background mode only apiUrl will be used to send location update.

A location object we will send to you api or callback function contains:

latitude: the latitude in degrees
longitude: the longitude in degrees
altitude: the altitude in meters
timestamp: time of this location update, in milliseconds since Jan 1 1970
data: the data which was sent during call to start method
floor:(iOS Only) The logical floor of the building.
deviceID: Device Id
playerId: OneSignal Player Id(If Onesignal is enabled)
speed: The instantaneous speed of the device, measured in meters per second.
direction:(iOS Only) direction in which device is pointing. possible values are (N, NE, E, SE, S, SW, W, NW, N, (none))
horizontalAccuracy:(iOS Only) The radius of uncertainty for the location, measured in meters.
verticalAccuracy: The validity of the altitude values, and their estimated uncertainty, measured in meters.