Method reference

The React Native wrapper has methods for some commonly used methods in the native SDKs. Methods return a promise, which can be used to access objects and method results.

Example implementation

Initialise with your key

import RNHyperTrack from 'react-native-hypertrack';

export default class MyApp extends Component {
    constructor() {
        super();
        // Initialize HyperTrack wrapper
        RNHyperTrack.initialize(config.HT_PUBLISHABLE_KEY);
    }
}

Methods

Name Parameters Description
initialize token: string Initialize the SDK and configure the publishable token
getPublishableKey - Get the configured token from the SDK
getOrCreateUser name: string, phone: string, lookupId: string Create a new user to identify the current device
setUserId userId: string Set an identifier for the SDK by using an existing user id
getUserId - Get the current user id configured in the SDK
isTracking - Get true if the SDK is enabled and tracking, false otherwise
getETA latitude: double, longitude: double, vehicleType: string Get ETA to an expected location from user's current location. Vehicle type can be "car", "bicycle", "van", "walking", "three-wheeler", "motorcycle"
getCurrentLocation - Get user's current location
startTracking - Enable the SDK and start tracking
stopTracking - Disable the SDK and stop tracking
createAndAssignAction params: dict object Method to create and assign action to the user
completeAction actionId: string Complete an action from the SDK

Permission & Location Services Methods

Name Parameters Description
locationAuthorizationStatus - Method to check location authorization status for the app. Returns one of authorizedAlways, authorizedWhenInUse, denied, restricted, notDetermined with the promise.
requestLocationAuthorization title: string, message: string Method to request location (Always use) authorization. In Android, title and message can be specified to customize permission dialog box's title and message.
requestLocationWhenInUseAuthorization title: string, message: string Method to request location (When in use) authorization. In Android, title and message can be specified to customize permission dialog box's title and message.
locationServicesEnabled - Method to check location services are enabled or not.
requestLocationServices - Method to request location services for the device.
canAskMotionPermissions (For iOS only) actionId: string Method to check if motion activity API is available on the device or not.
requestMotionAuthorization (For iOS only) actionId: string Method to request motion authorization.

HyperTrack Error Codes

Error Type Code
PUBLISHABLE_KEY_NOT_CONFIGURED 100
USER_ID_NOT_CONFIGURED 102
LOCATION_PERMISSIONS_NOT_REQUESTED 104
LOCATION_SERVICES_DISABLED 105
INVALID_LOCATION_RECEIVED 121
INVALID_ETA_RECEIVED 122
INVALID_PARAMS 123
SERVER_ERROR 141
JSON_ERROR 142
UNHANDLED_ERROR 151

Location changed events

It is possible to listen for location changed events in the Android and iOS implementations. The event name is location.changed.

Android

Use the DeviceEventEmitter method to listen for location.changed event. Each event has the location as a geojson object inside event.geojson.

componentWillMount: function() {
    DeviceEventEmitter.addListener('location.changed', function(e: Event) {
        // handle event.
        console.log(e.geojson) // Prints geojson object in the event.
    });
}

iOS

Use the NativeEventEmitter method to listen for location.changed event. Each event has the location as a geojson object inside event.geojson.

import { NativeEventEmitter } from 'react-native';

const locationEmitter = new NativeEventEmitter(RNHyperTrack);

const subscription = locationEmitter.addListener(
    'location.changed',
    (event) => console.log(event.geojson)
);

Get ETA to a location

HyperTrack.getETA API fetches ETA from the device's current location to a given expected location. The requirement for this API is the SDK to be initialized and Location Settings & Network connectivity to be enabled.

var vehicleType = "car"
RNHyperTrack.getETA(latitude, longitude, vehicleType).then((success) => {
        // Handle getCurrentLocation API success here
        console.log('getCurrentLocation success: ', success)
  }, (error) => {
      // Handle getCurrentLocation API error here
      console.log('getCurrentLocation error: ', error)
  })

Get Current Location

HyperTrack.getCurrentLocation API allows you to fetch device's current location. Only requirement for this API is the SDK to be initialized and Location Settings to be enabled.

RNHyperTrack.getCurrentLocation().then((success) => {
        // Handle getCurrentLocation API success here
        console.log('getCurrentLocation success: ', success)
    }, (error) => {
        // Handle getCurrentLocation API error here
        console.log('getCurrentLocation error: ', error)
    })

Returns a dictionary containing the location parameters as depicted below:

{ altitude: 10,
  speed: -1,
  longitude: 77.16159782960666,
  accuracy: 165,
  bearing: 10,
  latitude: 28.562211514248595,
  verticalAccuracy: 226.06683349609375 }

results matching ""

    No results matching ""