Argeoanchor在REALEKIT应用程序中给我错误的坐标
我正在尝试在我在屏幕上触摸的飞机上添加一个地理学家。我已经设置了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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须等待
arsession.currentframe
才能报告.localized
的geotrackingstatus。然后GetGeotocation将起作用。You have to wait for the
ARSession.currentFrame
to report a geoTrackingStatus of.localized
. Then getGeoLocation will work.