HyperTrackβ
This plugin is still in beta stage and may not work as expected. Please submit any issues to the plugin repo.
HyperTrack cordova plugin wrapper for Ionic Native. Location-based services provider. Make sure to include your publishable key at config.xml (see HyperTrack Cordova Setup).
Repo: https://github.com/hypertrack/hypertrack-cordova
Installation
- Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add cordova-plugin-hypertrack $ npm install --save @ionic-native/hyper-track@4
- Add this plugin to your app's module
Supported platforms
- Android
Usage
import { HyperTrack } from '@ionic-native/hyper-track';
constructor(private hyperTrack: HyperTrack) { }
// Check if app has location permissions enabled
this.hyperTrack.checkLocationPermission().then(response => {
// response (String) can be "true" or "false"
if (response != "true") {
// Ask for permissions
this.hyperTrack.requestPermissions().then(response => {}, error => {});
}
}, error => {});
// Check if app has location services enabled
this.hyperTrack.checkLocationServices().then(response => {
// response (String) can be "true" or "false"
if (response != "true") {
// Request services to be enabled
this.hyperTrack.requestLocationServices().then(response => {}, error => {});
}
}, error => {});
// First set the current user. This can be done via getOrCreateUser() or setUserId()
this.hyperTrack.setUserId("xxx").then(user => {
// user (String) is a String representation of a User's JSON
this.hyperTrack.startTracking().then(userId => {}, trackingError => {});
this.hyperTrack.createAndAssignAction('visit', 'lookupId','address', 20.12, -100.3).then(action => {
// Handle action. It's a String representation of the Action's JSON. For example:
// '{"eta":"Jul 17, 2017 12:50:03 PM","assigned_at":"Jul 17, 2017 12:34:38 PM",,"distance":"0.0",...}'
}, error => {});
// You can complete an action with completeAction() or completeActionWithLookupId()
this.hyperTrack.completeAction('action-id').then(response => {
// Handle response (String). Should be "OK".
}, error => {});
this.hyperTrack.getCurrentLocation().then(location => {
// Handle location. It's a String representation of a Location's JSON.For example:
// '{"mAccuracy":22.601,,"mLatitude":23.123456, "mLongitude":-100.1234567, ...}'
}, error => {});
this.hyperTrack.stopTracking().then(success => {
// Handle success (String). Should be "OK".
}, error => {});
}, error => {});*
Instance Members
helloWorld(text)
Returns given text. For testing purposes.
Param | Type | Details |
---|---|---|
text |
String
|
Given text to print |
Returns: Promise<any>
Returns a Promise that resolves with the result text (which is the same as the given text) if successful, or it gets rejected if an error ocurred.
getOrCreateUser(name, phone, photo, lookupId)
Create a new user to identify the current device or get a user from a lookup id.
Param | Type | Details |
---|---|---|
name |
String
|
User's name |
phone |
String
|
User's phone |
photo |
String
|
User's photo as URL or a Base64 converted string |
lookupId |
String
|
User's lookupId, which is used to check if a new user is to be created (in this case you could set it to an internal reference for the user that you can use later to identify it), or if one with an existing lookupId is to be used. |
Returns: Promise<any>
Returns a Promise that resolves with a string representation of the User’s JSON, or it gets rejected if an error ocurred.
setUserId(userId)
Set UserId for the SDK created using HyperTrack APIs. This is useful if you already have a user previously created.
Param | Type | Details |
---|---|---|
userId |
String
|
User's ID |
Returns: Promise<any>
Returns a Promise that resolves with an “OK” string if successful, or it gets rejected if an error ocurred. An “OK” response doesn’t necessarily mean that the userId was found. It just means that it was set correctly.
startTracking()
Enable the SDK and start tracking. This will fail if there is no user set.
Returns: Promise<any>
Returns a Promise that resolves with the userId (String) of the User being tracked if successful, or it gets rejected if an error ocurred. One example of an error is not setting a User with getOrCreateUser() or setUserId() before calling this function.
createAndAssignAction(type, lookupId, expectedPlaceAddress, expectedPlaceLatitude, expectedPlaceLongitude)
Create and assign an action to the current user using specified parameters
Param | Type | Details |
---|---|---|
type |
String
|
The action type. Can be one from "pickup", "delivery", "dropoff", "visit", "stopover" or "task" |
lookupId |
String
|
The Action's desired lookupId |
expectedPlaceAddress |
String
|
The address of the Action |
expectedPlaceLatitude |
Number
|
The latitude of the Action |
expectedPlaceLongitude |
Number
|
The longitude of the Action |
Returns: Promise<any>
Returns a Promise that resolves with a string representation of the Action’s JSON, or it gets rejected if an error ocurred.
completeAction(actionId)
Complete an action from the SDK by its ID
Param | Type | Details |
---|---|---|
actionId |
String
|
ID of the Action that will be marked as completed |
Returns: Promise<any>
Returns a Promise that resolves with an “OK” string if successful, or it gets rejected if an error ocurred.
completeActionWithLookupId(lookupId)
Complete an action from the SDK using Action’s lookupId as parameter
Param | Type | Details |
---|---|---|
lookupId |
String
|
Lookup ID of the Action that will be marked as completed |
Returns: Promise<any>
Returns a Promise that resolves with an “OK” string if successful, or it gets rejected if an error ocurred.
stopTracking()
Disable the SDK and stop tracking. Needs user setting (via getOrCreateUser() or setUserId()) first.
Returns: Promise<any>
Returns a Promise that resolves with the an “OK” string if successful, or it gets rejected if an error ocurred. One example of an error is not setting a User with getOrCreateUser() or setUserId() before calling this function.
getCurrentLocation()
Get user’s current location from the SDK
Returns: Promise<any>
Returns a Promise that resolves with a string representation of the Location’s JSON, or it gets rejected if an error ocurred.
checkLocationPermission()
Check if Location permission has been granted to the app (for Android). Returns “true” or “false” in success method accordingly.
Returns: Promise<any>
Returns a Promise that resolves with the a string that can be “true” or “false”, depending if location permission was granted, or it gets rejected if an error ocurred.
requestPermissions()
Request user to grant Location access to the app (for Anrdoid). For Android Marshmallow and above. In other platforms, the Promise is never resolved.
Returns: Promise<any>
Returns a Promise that resolves with the a string that can be “true” or “false”, depending if Location access was given to the app, or it gets rejected if an error ocurred.
checkLocationServices()
Check if Location services are enabled on the device (for Android). Returns “true” or “false” in success method accordingly.
Returns: Promise<any>
Returns a Promise that resolves with the a string that can be “true” or “false”, depending if location services are enabled, or it gets rejected if an error ocurred.
requestLocationServices()
Request user to enable Location services on the device. For Android Marshmallow and above. In other platforms, the Promise is never resolved.
Returns: Promise<any>
Returns a Promise that resolves with the a string that can be “true” or “false”, depending if Location services were enabled, or it gets rejected if an error ocurred.