Learn how to use Cloud Anchors in your own apps.
Enable the ARCore API
Before using Cloud Anchors in your app, you must first enable the ARCore API in your application.
Enable Cloud Anchor capabilities in the session configuration
Once Cloud Anchors functionality has been enabled in your app, enable Cloud Anchors capabilities in your app’s AR session configuration so that it can communicate with the ARCore API:
// Create a new ARCore session. ArSession* session = NULL; CHECK(ArSession_create(env, context, &session) == AR_SUCCESS); // Create a session config. ArConfig* config = NULL; ArConfig_create(session, &config); ArSession_getConfig(session, config); // Enable Cloud Anchor mode. ArConfig_setCloudAnchorMode(session, config, AR_CLOUD_ANCHOR_MODE_ENABLED); // Configure the session. ArSession_configure(session, config); ArConfig_destroy(config);
Host a Cloud Anchor
Hosting starts with a call to
ArSession_hostCloudAnchorAsync(). ARCore will upload visual data, device poses, and the anchor pose to the ARCore API. The API then processes this information to construct a 3D feature map, ultimately returning a unique Cloud Anchor ID for the anchor to the device.
You can also extend the lifetime of a hosted anchor using the ARCore Cloud Anchor Management API.
Your app should follow these steps to complete hosting of a Cloud Anchor:
- Wait for the callback, or continually check the Future state until it is done.
- Check the result state to determine if the operation succeeded, or interpret the error code if it failed.
- Share the result Cloud Anchor ID with other clients, and use it to resolve the Cloud Anchor with
Check the mapping quality of feature points
ArFeatureMapQuality indicates the quality of feature points seen by ARCore in the preceding few seconds from a given camera pose. Cloud Anchors hosted using higher quality features are generally more accurately resolved. Use
ArSession_estimateFeatureMapQualityForHosting() to obtain an estimation for the feature map quality for a given camera pose.
|The quality of feature points identified from the pose in the preceding few seconds is low. This state indicates that ARCore will likely have more difficulty resolving the Cloud Anchor. Encourage the user to move the device so that the desired position of the Cloud Anchor that they wish to host can be viewed from different angles.
|The quality of feature points identified from the pose in the preceding few seconds is likely sufficient for ARCore to successfully resolve a Cloud Anchor, although the accuracy of the resolved pose will likely be reduced. Encourage the user to move the device so that the desired position of the Cloud Anchor that they wish to host can be viewed from different angles.
|The quality of feature points identified from the pose in the preceding few seconds is likely sufficient for ARCore to successfully resolve a Cloud Anchor with a high degree of accuracy.
Resolve a previously hosted anchor
ArSession_resolveCloudAnchorAsync() to resolve a hosted Cloud Anchor. The ARCore API periodically compares visual features from the scene against the anchor’s 3D feature map to pinpoint the user's position and orientation relative to the anchor. When it finds a match, the API returns the pose of the hosted Cloud Anchor.
You can initiate resolves for multiple Cloud Anchors in sequence. Up to 40 concurrent Cloud Anchor operations can exist at a time.
Cancel an operation or remove a Cloud Anchor
ArFuture_cancel() to cancel a pending Cloud Anchor operation.
ArAnchor_detach() to stop tracking and forget an already-resolved Cloud Anchor. References to the anchor must be released separately by calling
Check the result state of a Cloud Anchor operation
Use ArCloudAnchorState to check the result status of the hosting or resolving operation, including errors.
|Resolving failed because the ARCore API could not find the provided Cloud Anchor ID.
|Hosting failed because the server could not successfully process the dataset for the given anchor. Try again after the device has gathered more data from the environment.
|The ARCore API was unreachable. This can happen for a number of reasons. The device might be in airplane mode or may not have a working Internet connection. The request sent to the server might have timed out with no response. There might be a bad network connection, DNS unavailability, firewall issues, or anything else that might affect the device's ability to connect to the ARCore API.
|A hosting or resolving task for this anchor finished with an internal error. The app should not attempt to recover from this error.
|See Troubleshooting problems with ARCore API authorization.
|The Cloud Anchor could not be resolved because the SDK version used to resolve the anchor is newer than, and incompatible with, the version used to host it.
|The Cloud Anchor could not be resolved because the SDK version used to resolve the anchor is older than, and incompatible with, the version used to host it.
|The application has exhausted the request quota allotted to the given Google Cloud project. You should request additional quota for the ARCore API for your project from the Google Developers Console.
|A hosting or resolving task for this anchor completed successfully.
API quotas for host and resolve requests
The ARCore API has the following quotas for request bandwidth:
|Number of anchors
|Anchor host requests
|IP address and project
|Anchor resolve requests
|IP address and project
Best practices for a good user experience
Instruct users to do the following to ensure a good user experience on your app:
- Wait a few seconds after the session starts before attempting to host an anchor (by placing an object, etc.). This gives the tracking some time to stabilize.
- When selecting a location to host the anchor, try to find an area with visual features that are easily distinguishable from one another. For best results, avoid reflective surfaces or surfaces that lack visual features, such as blank white walls.
Keep the camera trained on the center of interest and move the device around the center of interest to map the environment from different angles, maintaining roughly the same physical distance as you do so. This will help capture more visual data and make resolving more robust.
Make sure that there is sufficient lighting in the real-life environment while hosting and resolving Cloud Anchors.
- Apps built with ARCore SDK 1.12.0 or higher are covered by the Cloud Anchor API deprecation policy.
- Apps built with ARCore SDK 1.11.0 or lower are unable to host or resolve Cloud Anchors due to the SDK's use of an older, deprecated ARCore API.
- Check out the Android NDK reference documentation for more ways to use ARCore in your app.