@radarlabs/cordova-plugin-radar
Advanced tools
Comparing version 0.0.3 to 3.0.0-alpha.1
@@ -6,7 +6,7 @@ { | ||
"license": "Apache-2.0", | ||
"version": "0.0.3", | ||
"version": "3.0.0-alpha.1", | ||
"main": "www/Radar.js", | ||
"devDependencies": { | ||
"babel-eslint": "^7.1.1", | ||
"eslint": "^3.14.0", | ||
"eslint": "^4.18.2", | ||
"eslint-config-airbnb": "^14.0.0", | ||
@@ -13,0 +13,0 @@ "eslint-plugin-import": "^2.2.0", |
167
README.md
@@ -5,167 +5,12 @@ ![Radar](https://raw.githubusercontent.com/radarlabs/cordova-plugin-radar/master/logo.png) | ||
[Radar](https://radar.io) is the location platform for mobile apps. | ||
[Radar](https://radar.io) is location data infrastructure. You can use Radar SDKs and APIs to add location context to your apps with just a few lines of code. | ||
## Installation | ||
## Documentation | ||
Install the Cordova plugin: | ||
See the Radar overview documentation [here](https://radar.io/documentation). | ||
```bash | ||
$ cordova plugin add @radarlabs/cordova-plugin-radar | ||
``` | ||
Then, see the Radar Capacitor plugin documentation [here](https://radar.io/documentation/sdk/capacitor). | ||
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](https://radar.io/documentation/sdk). | ||
## Support | ||
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. | ||
```objc | ||
#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: | ||
```java | ||
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: | ||
```js | ||
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](https://help.radar.io/privacy/what-are-privacy-best-practices-for-radar) for more information. | ||
To set an optional description for the user, displayed in the dashboard, call: | ||
```js | ||
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: | ||
```js | ||
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: | ||
```js | ||
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: | ||
```js | ||
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: | ||
```js | ||
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](https://support.apple.com/en-us/HT205234), by Android [Doze Mode and App Standby](https://developer.android.com/training/monitoring-device-state/doze-standby.html) and [Background Location Limits](https://developer.android.com/about/versions/oreo/background-location-limits.html), 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](https://radar.io/documentation/sdk#accuracy).** | ||
To stop tracking the user's location in the background (e.g., when the user logs out), call: | ||
```js | ||
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: | ||
```js | ||
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: | ||
```js | ||
cordova.plugins.radar.offEvents(); | ||
cordova.plugins.radar.offError(); | ||
``` | ||
### Manual tracking | ||
You can manually update the user's location by calling: | ||
```js | ||
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 | ||
}); | ||
``` | ||
Have questions? We're here to help! Email us at [support@radar.io](mailto:support@radar.io). |
122
www/Radar.js
@@ -18,2 +18,6 @@ const cordova = require('cordova'); | ||
const setMetadata = (metadata) => { | ||
exec('setMetadata', [metadata]); | ||
}; | ||
const getPermissionsStatus = (callback) => { | ||
@@ -27,18 +31,34 @@ exec('getPermissionsStatus', null, callback); | ||
const startTracking = () => { | ||
exec('startTracking'); | ||
const getLocation = (callback) => { | ||
exec('getLocation', null, callback); | ||
}; | ||
const stopTracking = () => { | ||
exec('stopTracking'); | ||
const trackOnce = (arg1, arg2) => { | ||
if (typeof arg1 === 'function') { | ||
exec('trackOnce', null, arg1); | ||
} else { | ||
exec('trackOnce', [arg1], arg2); | ||
} | ||
}; | ||
const trackOnce = (callback) => { | ||
exec('trackOnce', null, callback); | ||
const startTrackingEfficient = () => { | ||
exec('startTrackingEfficient'); | ||
}; | ||
const updateLocation = (location, callback) => { | ||
exec('updateLocation', [location], callback); | ||
const startTrackingResponsive = () => { | ||
exec('startTrackingResponsive'); | ||
}; | ||
const startTrackingContinuous = () => { | ||
exec('startTrackingContinuous'); | ||
}; | ||
const startTrackingCustom = (options, callback) => { | ||
exec('startTrackingCustom', [options], callback); | ||
}; | ||
const stopTracking = () => { | ||
exec('stopTracking'); | ||
}; | ||
const onEvents = (callback) => { | ||
@@ -50,2 +70,14 @@ exec('onEvents', null, (data) => { | ||
const onLocation = (callback) => { | ||
exec('onLocation', null, (data) => { | ||
callback(data.location, data.user); | ||
}); | ||
}; | ||
const onClientLocation = (callback) => { | ||
exec('onClientLocation', null, (data) => { | ||
callback(data.location, data.stopped, data.source); | ||
}); | ||
}; | ||
const onError = (callback) => { | ||
@@ -61,2 +93,10 @@ exec('onError', null, (data) => { | ||
const offLocation = () => { | ||
exec('offLocation'); | ||
}; | ||
const offClientLocation = () => { | ||
exec('offClientLocation'); | ||
}; | ||
const offError = () => { | ||
@@ -66,17 +106,77 @@ exec('offEvents'); | ||
const getContext = (arg1, arg2) => { | ||
if (typeof arg1 === 'function') { | ||
exec('getContext', null, arg1); | ||
} else { | ||
exec('getContext', [arg1], arg2); | ||
} | ||
}; | ||
const searchPlaces = (options, callback) => { | ||
exec('searchPlaces', [options], callback); | ||
}; | ||
const searchGeofences = (options, callback) => { | ||
exec('searchGeofences', [options], callback); | ||
}; | ||
const searchPoints = (options, callback) => { | ||
exec('searchPoints', [options], callback); | ||
}; | ||
const autocomplete = (options, callback) => { | ||
exec('autocomplete', [options], callback); | ||
}; | ||
const geocode = (query, callback) => { | ||
exec('geocode', [query], callback); | ||
}; | ||
const reverseGeocode = (arg1, arg2) => { | ||
if (typeof arg1 === 'function') { | ||
exec('reverseGeocode', null, arg1); | ||
} else { | ||
exec('reverseGeocode', [arg1], arg2); | ||
} | ||
}; | ||
const ipGeocode = (callback) => { | ||
exec('ipGeocode', null, callback); | ||
}; | ||
const getDistance = (options, callback) => { | ||
exec('getDistance', [options], callback); | ||
}; | ||
const Radar = { | ||
setUserId, | ||
setDescription, | ||
setMetadata, | ||
getPermissionsStatus, | ||
requestPermissions, | ||
startTracking, | ||
getLocation, | ||
trackOnce, | ||
startTrackingEfficient, | ||
startTrackingResponsive, | ||
startTrackingContinuous, | ||
stopTracking, | ||
trackOnce, | ||
updateLocation, | ||
onEvents, | ||
onLocation, | ||
onClientLocation, | ||
onError, | ||
offEvents, | ||
offLocation, | ||
offClientLocation, | ||
offError, | ||
getContext, | ||
searchPlaces, | ||
searchGeofences, | ||
searchPoints, | ||
autocomplete, | ||
geocode, | ||
reverseGeocode, | ||
ipGeocode, | ||
getDistance, | ||
}; | ||
module.exports = Radar; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
89053
14
746
16
1