Argeoanchor在REALEKIT应用程序中给我错误的坐标

发布于 2025-02-05 18:33:56 字数 2149 浏览 4 评论 0原文

我正在尝试在我在屏幕上触摸的飞机上添加一个地理学家。我已经设置了ArgeotrackingConfiguration,如下所示:

func makeUIView(context: Context) -> ARView {
        
        let arView = ARView(frame: .zero)
        
        let session = arView.session
        let config = ARGeoTrackingConfiguration()
        
        config.planeDetection = .horizontal
        session.run(config)
        
        
        // Start listening for location updates from Core Location
        locationManager.requestWhenInUseAuthorization()
        locationManager.startUpdatingLocation()
        
        
        arView.addGestureRecognizer(UITapGestureRecognizer(target: context.coordinator, action: #selector(Coordinator.onTap)))
        context.coordinator.arView = arView
        
       
        
        return arView
    }

在我的协调员中,我执行以下操作:

 @objc func onTap(_ recognizer: UITapGestureRecognizer) {
        
        guard let arView = arView else {
            return
        }
        
        let location = recognizer.location(in: arView)
        let results = arView.raycast(from: location, allowing: .estimatedPlane, alignment: .any)
        
        if let result = results.first {
            
            arView.session.getGeoLocation(forPoint: result.worldTransform.translation) { coordinate, altitude, error in
                print(coordinate)
                let geoAnchor = ARGeoAnchor(coordinate: coordinate, altitude: altitude)
                let anchor = AnchorEntity(anchor: geoAnchor)
                let box = ModelEntity(mesh: MeshResource.generateBox(size: 0.3), materials: [SimpleMaterial(color: .green, isMetallic: true)])
                anchor.addChild(box)
                arView.scene.addAnchor(anchor)
            }
        }
        
    }

GetGeococation函数始终将坐标返回为-180和-180,这是错误的。我所在地区有地理学家可用,但我不确定为什么他们不起作用。

In the documentation of arView.session.getGeoLocation it says "To succeed, this function requires an ARGeoTrackingConfiguration session with state equal to ARGeoTrackingStatus.State.localized". 

我不确定我应该在哪里设置argeotrackingstatus.state.localized。

任何帮助!

I am trying to add a GeoAnchor on the plane where I touch on the screen. I have set the ARGeoTrackingConfiguration as shown below:

func makeUIView(context: Context) -> ARView {
        
        let arView = ARView(frame: .zero)
        
        let session = arView.session
        let config = ARGeoTrackingConfiguration()
        
        config.planeDetection = .horizontal
        session.run(config)
        
        
        // Start listening for location updates from Core Location
        locationManager.requestWhenInUseAuthorization()
        locationManager.startUpdatingLocation()
        
        
        arView.addGestureRecognizer(UITapGestureRecognizer(target: context.coordinator, action: #selector(Coordinator.onTap)))
        context.coordinator.arView = arView
        
       
        
        return arView
    }

In my coordinator I do the following:

 @objc func onTap(_ recognizer: UITapGestureRecognizer) {
        
        guard let arView = arView else {
            return
        }
        
        let location = recognizer.location(in: arView)
        let results = arView.raycast(from: location, allowing: .estimatedPlane, alignment: .any)
        
        if let result = results.first {
            
            arView.session.getGeoLocation(forPoint: result.worldTransform.translation) { coordinate, altitude, error in
                print(coordinate)
                let geoAnchor = ARGeoAnchor(coordinate: coordinate, altitude: altitude)
                let anchor = AnchorEntity(anchor: geoAnchor)
                let box = ModelEntity(mesh: MeshResource.generateBox(size: 0.3), materials: [SimpleMaterial(color: .green, isMetallic: true)])
                anchor.addChild(box)
                arView.scene.addAnchor(anchor)
            }
        }
        
    }

The getGeoLocation function always returns the coordinates as -180 and -180, which is wrong. GeoAnchors are available in my area but I am not sure why they don't work.

In the documentation of arView.session.getGeoLocation it says "To succeed, this function requires an ARGeoTrackingConfiguration session with state equal to ARGeoTrackingStatus.State.localized". 

I am not sure where I am suppose to set the ARGeoTrackingStatus.State.localized.

Any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寻梦旅人 2025-02-12 18:33:56

您必须等待arsession.currentframe才能报告.localized的geotrackingstatus。然后GetGeotocation将起作用。

You have to wait for the ARSession.currentFrame to report a geoTrackingStatus of .localized. Then getGeoLocation will work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文