Skip to main content

Building an app with location-enabled curbside pickup

In this tutorial, we show you how to use the Radar iOS SDK, geofences, and trip tracking to build a "McRadar's" app with location-enabled curbside pickup.

Languages used#

  • Swift

Features used#

Steps#

Step 1: Sign up for Radar#

If you haven't already, sign up for Radar to get your API key. You can create up to 1,000 geofences and make up to 100,000 API requests per month for free.

Get API keys

Step 2: Import geofences#

On the Geofences page, create a geofence for a McRadar's location. In this case, use restaurant for the geofence tag and 123 for the geofence externalId.

Step 3: Install the Radar iOS SDK#

Install the Radar SDK using CocoaPods or Carthage (recommended) or by downloading the framework and dragging it into your project.

Initialize the SDK in your AppDelegate class with your publishable API key, then request location permissions.

import UIKitimport CoreLocationimport RadarSDK
@UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate {
    let locationManager = CLLocationManager()
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {        Radar.initialize(publishableKey: "prj_test_pk_...")
        self.locationManager.requestWhenInUseAuthorization()
        return true    }
}

Step 4: Start tracking and start a trip#

When the user places an order and taps "I'm on my way," start tracking to start live location tracking, start a trip to the destination geofence. Use the order ID, in this case 456, for the trip externalId.

let tripOptions = RadarTripOptions(externalId: "456")tripOptions.destinationGeofenceTag = "restaurant"tripOptions.destinationGeofenceExternalId = "123"tripOptions.mode = .carRadar.startTrip(options: tripOptions, trackingOptions: .presetContinuous)

Optionally, instead of calling Radar.startTracking(), we can simulate a sequence of location updates from an origin to a destination with Radar.mockTracking(). For example, to simulate a sequence of 10 location updates every 3 seconds by car from an origin to a destination, we can call:

Radar.mockTracking(  origin: CLLocation(latitude: 40.714708, longitude: -74.035807),  destination: CLLocation(latitude: 40.717410, longitude: -74.053334),  mode: .car,  steps: 10,  interval: 3) { (status, location, events, user) in
}

Step 5: Display live ETAs in the trip tracking dashboard#

Display live ETAs on the trip tracking dashboard, available on the Enterprise plan. Or, display live ETAs in your own UI by polling the list trips API or listening for trip events sent to a webhook.

Step 6: Stop tracking and stop the trip#

When the user taps "I'm here" or when the order is picked up, complete the trip and stop tracking.

Radar.completeTrip()Radar.stopTracking()

Sample code#

// AppDelegate.swift
import UIKitimport CoreLocationimport RadarSDK
@UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate {
    let locationManager = CLLocationManager()
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {        Radar.initialize(publishableKey: "prj_test_pk_...")
        self.locationManager.requestWhenInUseAuthorization()
        return true    }
}
// ViewController.swift
import UIKitimport RadarSDK
class ViewController: UIViewController {
    var pickupStarted = false
    @IBAction func didTapButton(button: UIButton) {        if !pickupStarted {            let tripOptions = RadarTripOptions(externalId: "456")            tripOptions.destinationGeofenceTag = "restaurant"            tripOptions.destinationGeofenceExternalId = "123"            tripOptions.mode = .car            Radar.startTrip(options: tripOptions, trackingOptions: .presetContinuous)            sender.setTitle("I'm here", for: .normal)            pickupStarted = true        } else {            Radar.completeTrip()            Radar.stopTracking()            sender.setTitle("I'm here", for: .normal)            pickupStarted = false        }    }
}

Support#

Have questions or feedback on this documentation? Let us know! Email us at support@radar.com.