Model won't appear at location with ARGeoAnchor

Hi all,

I'm trying to display a 3d model from a usdz file at a particular location. Here's the code I came up with:

class ViewController: UIViewController, ARSessionDelegate {

    @IBOutlet var arView: ARView!
    var geoAnchor: ARGeoAnchor? = nil
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        arView.session.delegate = self
        let config = ARGeoTrackingConfiguration()
        arView.session.run(config)

        let coordinate = CLLocationCoordinate2DMake(0.0, -100.0) // coordinates omitted
        let geoAnchor = ARGeoAnchor(coordinate: coordinate)
        self.geoAnchor = geoAnchor
        arView.session.add(anchor: geoAnchor)
    }

    func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
        
        guard let geoAnchor = geoAnchor else { return }
        
        guard let usdzPath = Bundle.main.url(forResource: "myModelFile", withExtension: "usdz") else { 
            return 
        }
        let modelEntity = try! Entity.loadModel(contentsOf: usdzPath)
        let anchorEntity = AnchorEntity(anchor: geoAnchor)
        anchorEntity.addChild(modelEntity)
        
        arView.scene.addAnchor(anchorEntity)
    }
}

When I go out on the street, I'm asked for location/camera permissions and approve. After that, I get nothing as I face my camera towards the location.

Note: I'm in one of the supported cities for ARGeoTrackingConfiguration to work—I've also logged statements confirming its availability both on my device and in my city.

Does anyone have any idea what might be the issue?

Can you see what the ARGeoTrackingStatus is for your session? You can add a func session(_ session: ARSession, didChange geoTrackingStatus: ARGeoTrackingStatus) handler to your function and verify that ARKit is properly localizing. See this page under Coach the User as the Session Begins

Thank you! So I went ahead with the suggestion and the status I got was "Localized", so it seems the geolocation features are working.

Not sure why my model isn't appearing though—I can confirm the code that grabs the usdz file and creates an entity from it does execute, but nothing appears. The 3D model appears just fine when I view it inside Xcode.

There are a few user things that can potentially go wrong: The anchor might too far away for the object to display properly (object might just be a few pixel high or be behind clipping plane, depending on how you render). -> Make sure the LocationAnchor is very close (ideally < 10m) to where the user stands for debugging.
There might also be other rendering issues related to your asset, to troubleshoot I recommend attaching a primitive (eg a cube) to the GeoAnchor. There is also a chance the LocationAnchor appears much lower or higher than expected, depending on your local environment, make sure to also look up and down to check for that or use a user-defined altitude when creating it. You can also try building the sample app to make sure LocationAnchors work properly on your device and then swap out the blue spheres for your .usdz objects, see: https://developer.apple.com/documentation/arkit/content_anchors/tracking_geographic_locations_in_ar

Hey there emanh, did you find your answer and is the location based functionality working fully on your side?

Model won't appear at location with ARGeoAnchor
 
 
Q