google-ar / arcore-ios-sdk

ARCore SDK for iOS

Home Page:https://developers.google.com/ar/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Only receiving GARTrackingStatePaused for garSession

kevintbradbury opened this issue · comments

Hello,

I've been struggling to get the cameraGeospatialTransform from the garFrame in my own app. I've gone back and reviewed the sample ARCore app (Obj-C version) and can receive the transform data properly there. Please see the init code below.

func initialize() {
  self.scnView = ARSCNView(frame: self.frame)
  self.scnView?.translatesAutoresizingMaskIntoConstraints = false
  self.scnView?.automaticallyUpdatesLighting = true
  self.scnView?.autoenablesDefaultLighting = true
  self.scnView?.debugOptions = [
          .showFeaturePoints,
          .showWorldOrigin
      ]
  self.arKitSession = self.scnView?.session
  self.arKitSession?.delegate = self

  self.arConfig = ARWorldTrackingConfiguration()
  self.arConfig?.worldAlignment = .gravity
      
  if let config = arConfig {
          self.arKitSession?.run(config, options: .removeExistingAnchors)
          self.setupGARsession()
  }
}

private func setupGARsession() {
    do {
        self.garSession = try GARSession(
            apiKey: "<omitted>", bundleIdentifier: Bundle.main.bundleIdentifier ?? "<omitted>"
        )
        guard
            self.garSession?.isGeospatialModeSupported(GARGeospatialMode.enabled) == true
        else {
            throw NSError(domain: "Geospatial not supported", code: 0)
        }
        garSession?.delegate = self
        garSession?.delegateQueue = .main

        var error: NSError? = nil
        var config = GARSessionConfiguration()
        config.geospatialMode = .enabled
        
        self.garSession?.setConfiguration(config, error: &error)

        if error != nil {
            throw NSError(domain: error?.localizedDescription ?? "config error", code: 0)
        }
        
        if let lastCoordinate = viewModel.currentLocation?.coordinate {
            checkVPS(currentLocation: lastCoordinate)
        }
    } catch {
        Debug.log(.error, message: "Error initializing google AR session with error: \(error)")
        debugLabel.text = "Error initializing google AR session with error: \(error.localizedDescription)"
    }
}

func checkVPS(currentLocation: CLLocationCoordinate2D) {
    garSession?.checkVPSAvailability(coordinate: currentLocation) { availability in
        self.viewModel.vpsAvailability = availability

        if availability != .available {
            DispatchQueue.main.async {
                self.debugLabel.text = self.vpsAvailabilityString(availability)
            }
        }
    }
}

func session(_ session: ARSession, didUpdate frame: ARFrame) {
    if #available(iOS 16.0, *) {
        if frame.camera.trackingState != .normal { return }
    }
    
    guard let coordinate = viewModel.currentLocation?.coordinate else { return }
    guard self.viewModel.vpsAvailability == .available else {
        checkVPS(currentLocation: coordinate)
        return
    }
        self.gAR_frame = try! garSession?.update(frame)
        useGpsOrVps(nil)
}

The useGpsOrVps func check for earthState and trackingState but the tracking always returns as GARTrackingStatePaused any help is welcome, thanks.

Referencing this Swift version example: https://github.com/sinano1107/swift-geospatialapi-example/tree/main ,

  1. the garFrame goes from earthState enabled
  2. localizationState is set to preTracking
  3. Then on the next frame update the earthState is no longer enabled

My issue was that we often have to use GPS location simulation and after turning off location simulation, I began receiving coordinates. I suppose the assumption is that you won't be using the geospatialTransform if you aren't in the area where you plan to use it. But there is nothing explicit in the errors, that I am aware of anyways, that states that.