LocationDataProvider Protocol in ios

Options
Refract_Studio
Refract_Studio Posts: 18 🔥
edited November 2023 in General #1

Hi all,
This is Sam Jones just asked this question in office Hours. I cannot seem to get location passed to my lens. I am implementing the correct protocol, I can confirm that the "location" for the protocol is being updated, but my test custom lenses still seem to not work. So I must be missing something. Here is my code for the protocol.

import Foundation
import SCSDKCameraKit
import CoreLocation

class LocationDataProvider: NSObject, SCSDKCameraKit.LocationDataProvider, CLLocationManagerDelegate {
    public var location: CLLocation?
    private let locationManager = CLLocationManager()

    override init() {
        super.init()
        locationManager.delegate = self

        requestLocationPermission()
        locationManager.startUpdatingLocation()
    }

    func startUpdating(with parameters: LocationParameters) {

        locationManager.desiredAccuracy = parameters.desiredAccuracy
        locationManager.distanceFilter = parameters.distanceFilterMeters
        //locationManager.startUpdatingLocation()
    }

    func stopUpdating() {
        locationManager.stopUpdatingLocation()
    }

    private func requestLocationPermission() {
         switch CLLocationManager().authorizationStatus {
         case .notDetermined:
             CLLocationManager().requestWhenInUseAuthorization()
         case .authorizedWhenInUse, .authorizedAlways:
             print("location authorized")
         default:
             CLLocationManager().requestWhenInUseAuthorization()
             print("location not authorized")
         }
     }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        guard let lastLocation = locations.last else { return }

        location = lastLocation
        print("location: \(location)")
    }    
}

and here is how I am using it

class CustomizedCameraController: CameraController {

    override func configureDataProvider() -> DataProviderComponent {
        DataProviderComponent(
            deviceMotion: nil, userData: UserDataProvider(), lensHint: nil, location: LocationDataProvider(),
            mediaPicker: lensMediaProvider, remoteApiServiceProviders: [CatFactRemoteApiServiceProvider()])
    }

}

thanks for your help!

Tagged:

Comments

  • stevenxu
    stevenxu Posts: 603 👻
    Options

    Thanks for posting on the forum @Refract_Studio ! Confirming receipt and ticket created. Our team will get back to you as soon as they can.

  • Refract_Studio
    Options

    thank you @stevenxu !

  • arashp
    arashp Posts: 52 🔥🔥
    Options

    Hi Sam, sorry for the delay here. This code looks correct and I assume you are passing in configureDataProvider() into your Camera Kit session. The issue may be with your test custom lens. Have you try it with Buckingham Palace? It is a template found in Lens Studio.

    If you can get Buckingham Palace working, then it might be worth comparing your Lens with that one. It seems like the iOS code is updating the location and passing it to Camera Kit. But the Lens is not responding.

    For this test, hardcode the location for Buckingham Palace in your custom LocationDataProvider:

    CLLocation(latitude: 51.5017108, longitude: -0.141184)

    Does this test work as expected?
    cc: @Refract_Studio

  • Refract_Studio
    Refract_Studio Posts: 18 🔥
    edited December 2023 #5
    Options

    @arashp sorry for the delay in responding I somehow missed the notification. I will try your suggestion today. My test scenario is set up like this:

    Created custom landmarker of my living room with default custom location template. No changes to the template other than using my test location ID.

    Thanks for your help, ya'll are great.