Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@radarlabs/cordova-plugin-radar

Package Overview
Dependencies
Maintainers
4
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radarlabs/cordova-plugin-radar

Cordova plugin for Radar, the location platform for mobile apps

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16
increased by77.78%
Maintainers
4
Weekly downloads
 
Created
Source

Radar

npm version

Radar is the location platform for mobile apps.

Installation

Install the Cordova plugin:

$ cordova plugin install cordova-plugin-radar

The Cordova plugin installs the Radar SDK using CocoaPods.

Before writing any JavaScript, you must integrate the Radar SDK with your iOS and Android apps by following the Configure project and Add SDK to project steps in the SDK documentation.

On iOS, you must add location usage descriptions and background modes to your Info.plist. Initialize the SDK in application:didFinishLaunchingWithOptions: in AppDelegate.m, passing in your publishable API key.

#import <RadarSDK/RadarSDK.h>

// ...

[Radar initializeWithPublishableKey:publishableKey];

On Android, you must add the Google Play Services library to your project. Initialize the SDK in onCreate() in MainApplication.java, passing in your publishable API key:

import io.radar.sdk.Radar;

// ...

Radar.initialize(publishableKey);

Usage

Identify user

Until you identify the user, Radar will automatically identify the user by device ID.

To identify the user when logged in, call:

cordova.plugins.radar.setUserId(userId);

where userId is a stable unique ID string for the user.

Do not send any PII, like names, email addresses, or publicly available IDs, for userId. See privacy best practices for more information.

To set an optional description for the user, displayed in the dashboard, call:

cordova.plugins.radar.setDescription(description);

where description is a string.

You only need to call these methods once, as these settings will be persisted across app sessions.

Request permissions

Before tracking the user's location, the user must have granted location permissions for the app.

To determine the whether user has granted location permissions for the app, call:

cordova.plugins.radar.getPermissionsStatus().then((status) => {
  // do something with status
});

status will be a string, one of:

  • GRANTED
  • DENIED
  • UNKNOWN

To request location permissions for the app, call:

cordova.plugins.radar.requestPermissions(background);

where background is a boolean indicating whether to request background location permissions or foreground location permissions. On Android, background will be ignored.

Foreground tracking

Once you have initialized the SDK, you have identified the user, and the user has granted permissions, you can track the user's location.

To track the user's location in the foreground, call:

cordova.plugins.radar.trackOnce().then((result) => {
  // do something with result.location, result.events, result.user.geofences
}).catch((err) => {
  // optionally, do something with err
});

err will be a string, one of:

  • ERROR_PUBLISHABLE_KEY: the SDK was not initialized
  • ERROR_USER_ID: the user was not identified
  • ERROR_PERMISSIONS: the user has not granted location permissions for the app
  • ERROR_LOCATION: location services were unavailable, or the location request timed out
  • ERROR_NETWORK: the network was unavailable, or the network connection timed out
  • ERROR_UNAUTHORIZED: the publishable API key is invalid
  • ERROR_SERVER: an internal server error occurred
  • ERROR_UNKNOWN: an unknown error occurred

Background tracking

Once you have initialized the SDK, you have identified the user, and the user has granted permissions, you can start tracking the user's location in the background.

To start tracking the user's location in the background, call:

cordova.plugins.radar.startTracking();

Assuming you have configured your project properly, the SDK will wake up while the user is moving (usually every 3-5 minutes), then shut down when the user stops (usually within 5-10 minutes). To save battery, the SDK will not wake up when stopped, and the user must move at least 100 meters from a stop (sometimes more) to wake up the SDK. Note that location updates may be delayed significantly by iOS Low Power Mode, by Android Doze Mode and App Standby and Background Location Limits, or if the device has connectivity issues, low battery, or wi-fi disabled. These constraints apply to all uses of background location services on iOS and Android, not just Radar. See more about accuracy and reliability.

To stop tracking the user's location in the background (e.g., when the user logs out), call:

cordova.plugins.radar.stopTracking();

You only need to call these methods once, as these settings will be persisted across app sessions.

To listen for events and errors, you can add event listeners:

cordova.plugins.radar.onEvents((events, user) => {
  // do something with events, user
});

cordova.plugins.radar.onError((err) => {
  // do something with err
});

You should remove event listeners when you are done with them:

cordova.plugins.radar.offEvents();

cordova.plugins.radar.offError();

Manual tracking

You can manually update the user's location by calling:

const location = {
  latitude: 39.2904,
  longitude: -76.6122,
  accuracy: 65
};

cordova.plugins.radar.updateLocation(location).then((result) => {
  // do something with result.events, result.user.geofences
}).catch((err) => {
  // optionally, do something with err
});

FAQs

Package last updated on 25 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc