• Using Apple’s ARKit to Navigate Back to Your Parked Car

    180413_arkit_1055x514

    Have you ever spent a good amount of time looking for the right spot to park your car or finding your parked car? If yes, then you need not worry any longer, as there are several mobile apps that can assist you on the same. In this Blog, we will delve into one such App, Apple’s ARKit.

    About Apple’s ARKit

    ARKit, is a framework launched by Apple in June 2017, enables developers to build augmented-reality (AR) apps for iOS 11. With the help of daily use cases discovered, Apple’s ARKit has great potential to expand. It is capable of handling tough tasks related to AR such as surface detection, motion tracking, and light matching.

    Using ARKit, you will be able to:

    • Remember where you’ve parked your car.
    • Navigate you back to your parked car.
    • Give you directions or routes to reach out your car.

    Using ARKit

    Once you park your car, you need to open your ARKit app and click on “Start” to mark the parked car. No matter where you are, be it at work or elsewhere, ARKit detects your car with the help of a GPS or camera sensor.

    ARkit_5-1

    If you look at the above screenshot, you will see:

    • a white up arrow on the left which indicates that the car is up ahead
    • a white text “10 m” on the right which indicates that the car is 10 meters ahead
    • a text in orange “Your Car” with an arrow sign which shows where the car is exactly parked
    • Dots in red with numbers which shows the route to the car

    You need to implement ‘Car Parking App’ in use case where the app will recall where you had parked your car. As a user, all you need is to mark the car parked spot on your iPhone app, and then walk away. Once you reach your destination or get away from the sizable position, the tracking will stop.

    Implementing the Apple ARKit App

    Apple’s ARKit shows a live view of the parked car with Augmented Reality (AR) location anchor points. These points are used to mark the location of the parked car as shown below:

    
    // Add Initial point
    
    let sphere = SCNSphere(radius: 0.1)
    
    let sphereNode = SCNNode(geometry: sphere)
    
    // Set the scene to the view
    
    let initialCarLocation = SCNVector3(x: 0, y: 0, z: 0)
    
    sphereNode.position = initialCarLocation
    
    // Add label on scene view for Initial point
    
    addTextOnScene(text: "Initial Point", position: sphereNode.position)
    
    self.sceneView.scene.rootNode.addChildNode(sphereNode)
    
    // Start counting distance and steps using pedometer
    
    startCountingSteps()
    
    // Get user latitude and longitude
    
    addLocationUpdates()
    

    It even connects your device with the GPS to track the location of the car. This even displays the distance between the user and the car. The moment you make your move, the pedometer counts your steps:

    
    func startCountingSteps() {
    
    self.pedoMeter.startUpdates(from: Date()) {
    
    [weak self] pedometerData, error in
    
    guard let pedometerData = pedometerData, error == nil else { return }
    
    DispatchQueue.main.async {
    
    let pedometerDistance = Double(truncating: pedometerData.distance!)
    
    let distance = Double(round(pedometerDistance))
    
    self?.lblDistance?.text = "\(distance) m"
    
    // Add marker on scene view after set steps
    
    if pedometerData.numberOfSteps.intValue >= (self?.stepCounterRange)! + (self?.steps)! {
    
    self?.steps = pedometerData.numberOfSteps.intValue
    
    // Add marker on scene view after 5 step
    
    self?.addPointInPlain()
    
    }
    
    }
    
    }
    
    }
    

    Moreover, at every five steps, Apple ARKit tags you with the number 1, 2, 3… and so on, to keep a check on the user’s route. To stop the pedometer, you need to click on “Stop”

    
    func addPointInPlain() {
    
    if isRecordingSteps {
    
    let sphere = SCNSphere(radius: 0.1)
    
    let colorMaterial = SCNMaterial()
    
    colorMaterial.diffuse.contents = UIColor.red
    
    colorMaterial.locksAmbientWithDiffuse = true
    
    sphere.materials = [colorMaterial]
    
    let sphereNode = SCNNode(geometry: sphere)
    
               
    
    // Set the scene to the view
    
    let resultHitTest = sceneView.hitTest(self.sceneView.center, types: [ARHitTestResult.ResultType.featurePoint])
    
    guard let hitFeature = resultHitTest.first else {
    
    return
    
    }
    
               
    
    let hitPosition = SCNVector3Make(hitFeature.worldTransform.columns.3.x, hitFeature.worldTransform.columns.3.y, hitFeature.worldTransform.columns.3.z)
    
    sphereNode.position = hitPosition
    
    // Add Marker count label on scene view
    
    addTextOnScene(text: "\(counterPath)", position: hitPosition)
    
    // Increment the marker count
    
    counterPath = counterPath + 1
    
               
    
    self.sceneView.scene.rootNode.addChildNode(sphereNode)
    
               
    
    if let anchor = lastAnchorPoints {
    
    // Create a node line between the nodes
    
    let measureLine = LineNode(from: anchor, to: hitPosition, lineColor: UIColor.red)
    
    measureLine.name = "measureLine"
    
    // Add the Node to the scene.
    
    self.sceneView.scene.rootNode.addChildNode(measureLine)
    
    }
    
    lastAnchorPoints = hitPosition
    
    }
    
    }
    

    Now that we have learnt how to implement the ARKit, yet it is important to know that it comes with a minor drawback, which is when the recorded AR Location feature points is not continued. This happens when the app switched to background, terminated or the device is switched off, which automatically results in not showing the routes or location.

    To Conclude

    Apple’s ARKit, with the help of AR, is undoubtedly, a technology with great prospects. It merges the real as well as the virtual workspace to augment reality!

    To know more about Apple’s ARKit or if you are looking for any kind of digital assistance, feel free to contact us at info@netsolutions.com and get the best digital solution for a great customer experience!

    Kundan Singh

    About the Author

    Kundan Singh heads the .NET team at Net Solutions and has over 14 years of experience in Microsoft Technologies. He also heads the Software Engineering & Processes Group at Net Solutions and is responsible for delivering key .NET projects.

    Comments

     
     


    get in touch

    Ready to discuss your requirements?

    Request Free Consultation