WebToNative
  • Getting started
  • Plugin Setup
    • OneSignal Set Up
    • Google AdMob Setup
    • In App Purchase - iOS Setup
    • In App Purchase - Android Setup
    • Firebase Notification Integration - iOS Setup
  • Social Login Integrations
    • Getting the SHA Key for Google Login
    • Create Google OAuth Client Id
    • Facebook Login Configuration
  • Javascript APIS
    • Getting Started
    • Status Bar
    • Pull To Refresh
    • Close App
    • Device Info
    • Clear App Cache
    • OneSignal Push Notification
    • Download Files
    • Printing Options
    • AdMob
    • Geo Location
    • Load In External Browser
    • Barcode Scan
    • In App Purchase - iOS Integration
    • In App Purchase - Android Integration
    • Social Login
    • Facebook App Events
    • Bottom Navigation
    • Clipboard
    • Screen Control
    • Background Location
    • Native Contacts
    • iOS App Tracking Transparency
    • Google Firebase Analytics
    • Haptic Feedback
    • Google Firebase Notification
    • Apps Flyer
    • App Review
    • Calender - iOS
    • Calendar - Android
    • Biometric Authentication
    • Media Player
    • Notification View
    • Offer Card
    • Cookie Update
    • App Launch Detection
    • Download Manager
    • Dynamic App Icon
    • File Sharing
  • Website Plugins
    • Wordpress
      • Push notification (WooCommerce)
      • In-App Purchase
        • In-App Purchase (IAP) Configuration Guide for iOS and Android
        • In-App Purchase (WooCommerce)
        • In-App Purchase
      • Offercard
      • Biometric Authentication
      • Social Login
      • Webtonative media player
        • WebToNative Radio Player
        • MediaPlayer Native Control
    • Bubble.io
      • Customize Status Bar
      • Device-Based Element Visibility
      • Pull to Refresh (Android)
      • OneSignal Push Notification
        • Set External ID
        • Send Push Notification
        • Set/Remove Email or SMS Phone
        • Set Tag
      • Close App
      • Get Device Info
      • Clear App Cache (Android)
      • Screen Control
      • Facebook Events
        • Regular
        • Purchase
      • AdMob
      • Offercard
      • In-App Purchase
        • In-App Purchase (Android/iOS)
        • Get IAP Canceled Subscription List (iOS)
      • Social Login
      • Biometric Authentication
  • Shopify
    • Social Login
    • In-App Purchase
      • In-app purchase
    • Push Notification
      • Abandoned Cart
    • Status Bar Customization
    • Native Device Visibilty
    • Set Onesignal Tags
    • Pull to Refresh
    • Account Deletion
    • Biometric Authentication
  • Upload Apps
    • Android App
    • Ios App
Powered by GitBook
On this page
  • Call the method with the following data
  • Notes
  • Location Object

Was this helpful?

  1. Javascript APIS

Background Location

You'll need to import the javascript file in your website before starting from this .

To retrieve device location even when app is in background state

//to start recieving location updates
window.WTN.backgroundLocation.start({
 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 the following data

apiUrl (Mandatory): The API endpoint that will be called using the POST method to send location data.

  • Value Type: String

  • Example: https://backgrounlocation.free.beeceptor.com/

timeout: The time interval between API calls, measured in milliseconds.

  • Value Type: Number

  • Example: 1000 milliseconds = 1 second

data (Optional): Extra data to send along with the location update. Useful for identifying users or adding metadata. Can also use query parameters.

  • Value Type: JSON object

  • Example: { "keyName": "value" }

backgroundIndicator (Optional, iOS Only): Modifies the iOS status bar to indicate that the app is using location services when in the background.

  • Value Type: Boolean

  • Default Value: false

pauseAutomatically (Optional, iOS Only): When set to "true," The location manager pauses updates (and powers down hardware) when location data is unlikely to change, improving battery life.

  • Value Type: Boolean

  • Default Value: true

distanceFilter: The minimum horizontal distance (in meters) a device must move before an update is generated.

  • Value Type: Double

  • Default Value: 0.0 meters

  • Example: If set to 10.0, data is logged only after the device moves 10 meters.

desiredAccuracy (Optional, iOS Only): The desired accuracy of location data. Higher accuracy increases battery consumption.

  • Value Type: String

  • Default Value: best

  • Possible Values:

    • best : The best accuracy possible (default).

    • bestForNavigation: Highest accuracy using additional sensor data for navigation apps.

    • tenMeters: Accurate to within 10 meters.

    • hundredMeters: Accurate to within 100 meters.

    • kilometer: Accurate to the nearest kilometer.

    • threekilometers: Accurate to the nearest 3 kilometers.

activityType (Optional, iOS Only): The user activity associated with location updates.

  • Value Type: String

  • Default Value: other

  • Possible Values:

    • other: Unknown activity (default).

    • automotiveNavigation: Vehicular navigation for automobiles.

    • otherNavigation: Non-automobile vehicular navigation.

    • fitness: Tracking fitness activities (e.g., walking, running, cycling).

    • airborne: Tracking airborne activities.

Notes

  • Foreground Behavior: Location updates are sent to both the callback function and apiUrl.

  • Background Behavior: Location updates are sent only to apiUrl when the app is in the background.

Location Object

The location data sent to your API or callback function includes the following fields:

  • latitude: Latitude in degrees.

  • longitude: Longitude in degrees.

  • altitude: Altitude in meters.

  • timestamp: Time of the location update (milliseconds since Jan 1, 1970).

  • data: The extra data provided in the start method.

  • floor (iOS Only): The logical floor of the building.

  • deviceID: Device identifier.

  • playerId: OneSignal Player ID (if OneSignal is enabled).

  • speed: Instantaneous speed of the device (meters per second).

  • direction (iOS Only): Device pointing direction (e.g., N, NE, E, SE, S, SW, W, NW, or none).

  • horizontalAccuracy (iOS Only): Radius of uncertainty for the location (in meters).

  • verticalAccuracy: Validity and estimated uncertainty of altitude values (in meters).


PreviousScreen ControlNextNative Contacts

Last updated 18 days ago

Was this helpful?