4

I have been reading around the documentation and the examples but still cant figure out a way to use ARCore/Sceneform with geolocations. An example would be opening my camera and according to my geo location and other places' geolocation I would render them on the camera if my camera was on the same compass direction as the object.

Can someone point me in the right direction of where I should be looking at and any guidance and is there something I can use from ARCore/Sceneform that would help with that?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
N Jay
  • 1,774
  • 1
  • 17
  • 36

2 Answers2

1

ARCore's Geospatial API

With ARCore 1.31 Geospatial API you can obtain geospatial data from Google Earth 3D and Street View images (from Google Maps), to enable your ARCore app for global-scale location-based AR experiences. This data model, taken from billions of images, is provided with Google VPS.

To enable Geospatial API use the following code:

fun configureSession(session: Session) {
    session.configure(
        session.config.apply {
            geospatialMode = Config.GeospatialMode.ENABLED
        }
    )
}

Then check if an object's TrackingState is TRACKING:

val earth = session?.earth ?: return

if (earth.trackingState != TrackingState.TRACKING) { return }

Now, you're ready to determine a pose of a new anchor:

val altitude = earth.cameraGeospatialPose.altitudeMeters - 1

val qtrnX = 0f; val qtrnY = 0f; val qtrnZ = 0f; val qtrnW = 1f;

earthAnchor = earth.createAnchor(latLng.latitude, 
                                 latLng.longitude, 
                                 altitude, qtrnX, qtrnY, qtrnZ, qtrnW)

Geospatial supported areas

Before using the Geospatial API, make sure the area you are in is supported.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • Hi Andy, is there any plan for you to write a sample project using geospatial API with SwiftUI + Realitykit in medium? I really want to learn how it works all together. Thanks Andy! – Frank Lan May 18 '22 at 07:15
0

I think there's nothing Sceneform specific to help you but I have some ideas: 1. The coordinate system is in meters which should help you to make the needed calculations. 2. You could let the user hold the device upright (check it via sensors) and get use the Camera pose to align it with all sensors you want to use like Compass and Geolocation. Position everything relative to this position. You maybe also want to create an Anchor to that position on order to keep everything updated as ARCore's understanding of the world improves.

Steven Mohr
  • 1,167
  • 6
  • 19