LocationDataProvider Protocol in ios

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() {
        locationManager.delegate = self


    func startUpdating(with parameters: LocationParameters) {

        locationManager.desiredAccuracy = parameters.desiredAccuracy
        locationManager.distanceFilter = parameters.distanceFilterMeters

    func stopUpdating() {

    private func requestLocationPermission() {
         switch CLLocationManager().authorizationStatus {
         case .notDetermined:
         case .authorizedWhenInUse, .authorizedAlways:
             print("location authorized")
             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 {
            deviceMotion: nil, userData: UserDataProvider(), lensHint: nil, location: LocationDataProvider(),
            mediaPicker: lensMediaProvider, remoteApiServiceProviders: [CatFactRemoteApiServiceProvider()])


thanks for your help!



  • stevenxu
    stevenxu Posts: 611 👻

    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

    thank you @stevenxu !

  • arashp
    arashp Posts: 52 🔥🔥

    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

    @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.