Live tracking in your app

A Task is a transaction event, like a pickup, or a visit that is performed by the Driver. While the task is performed, it can be tracked in real-time on a map inside an app, with relevant information like the details of the driver.

For this guide, we will create a demo task and track it on map inside iOS. If you're on Android, read the Android version of this guide.

Step 1: Install the SDK

To install the SDK, you will need CocoaPods. In your project directory, create a Podfile with the following content to add HTConsumer pod to your project. Once the Podfile is configured, install the SDK with the following command.

[warning] Xcode workspace

As with CocoaPods installations, use the .xcworkspace project file to open it in Xcode after the pods have been installed.

use_frameworks!

target 'YourApp' do
   pod 'HTConsumer'
end
$ pod install

[info] Example app

If you are looking for an example integration, you can use our example iOS app.

Step 2: Configure the SDK

Once the pods have been installed, we can use the SDK methods inside Xcode. The first step is to configure your publishable key in the SDK.

In Objective-C, configure the SDK in application:didFinishLaunchingWithOptions: method of the AppDelegate.

In Swift, configure the SDK in application(_:didFinishLaunchingWithOptions:) method of the AppDelegate.

Configure iOS SDK

@import HyperTrack;

@implementation AppDelegate

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

  [HyperTrack setPublishableAPIKey:@"YOUR_PUBLISHABLE_KEY"];
  return YES;
}

@end
import HTConsumer

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    //Initialize SDK
    HyperTrack.setPublishableAPIKey("YOUR_API_KEY")
    // Override point for customization after application launch.
    return true
}

Step 3: Setup view controller

In your Main.storyboard file, update your ViewController to UINavigationController. To do this, select ViewController in storyboard and got to Product menu and embed it in Navigation Controller.

Next, we will change the class of the ViewController from UIViewController to HTMapViewController. To do this import HTConsumer and rename the super class of ViewController to HTMapViewController.

Map view controller

Step 4: Modify the view

To properly display the map view in the view controller, we should not extend it below the edges of the navigation controller. To do this, select navigation controller in your Main.storyboard and deselect Under Top Bars and Under Bottom Bars.

Navigation edges setting

Step 5: Create demo task

In this step, we will call the HyperTrack API to create a demo Task object. This API creates a Task, and returns its id, which will be used in the next step.

[info] Secret key

Since we are creating a new Task object, this will require the secret key of your account.

curl -H "Authorization: token YOUR_SK_TOKEN" \
     -X POST \
     https://app.hypertrack.io/api/v1/tasks/demo/

Step 6: Track task

The map view controller will be the data source for the map view. For this step, we will use the Task id generated in the previous step. Add the following to your ViewController class.

Map view controller

override func taskIDsToTrack(for mapView: HTMapView) -> [String] {
    return ["DEMO_TASK_ID"]
}

Step 7: Run the app

Now the view controlled has been configured, it's time to run the app.

Consumer preview

[success] Live tracking

The native live tracking experience is available for all tasks, and is also available on the web and Android. To know more about the live tracking use-case and UI customisations for the map view, read the live tracking tutorials.

Was this helpful? Yes, thanks! Not really

results matching ""

    No results matching ""