Get started with Cloud Anchors. This guide shows you how to:
- Set up your development environment for Cloud Anchors
- Try out hosting and resolving anchors in the Cloud Anchors sample app
If you are new to working with anchors, see Working with Anchors for an introduction.
Cloud Anchor capabilities and a sample app are included in the ARCore SDK for Android NDK.
This guide assumes that you have already installed and configured the ARCore SDK for Android NDK. If not, see the Quickstart for Android NDK for installation and setup instructions.
Use Cloud Anchors
Set up your development environment for working with Cloud Anchors and try out the sample app.
Open the sample app in the SDK
helloarcloudanchor sample app is included with the ARCore SDK for Android
In Android Studio, you can find it under:
Set up anchor ID sharing
The sample app uses Firebase for sharing Cloud Anchor IDs between devices. You can use a different solution in your own apps.
Set up Firebase storage in the sample app for sharing anchor IDs between user devices:
- Follow steps 1 through 5 in the Firebase instructions for manually adding Firebase to your app.
- Download the
google-services.jsonfile generated as part of adding Firebase to your app.
- In Android Studio, add the
google-services.jsonfile to your project's module folder. Typically, this is the
Add an API Key
To use Cloud Anchors, you'll need to add a Google ARCore Cloud Anchor API Key to your app.
Obtain an API Key. See Setting up API keys in the Google Cloud Platform Console Help Center if you are new to working with API keys.
Enable the ARCore Cloud Anchor API for your Google Cloud Platform project.
In Android Studio, add your ARCore Cloud Anchor API key to your project. To do this, include the API key in the following code and add it to
<meta-data android:name="com.google.android.ar.YOUR_API_KEY" android:value="YOUR_API_KEY"/>
Try out the sample app
Build and run the
helloarcloudanchor sample app to try out hosting and
resolving Cloud Anchors.
Make sure that developer options and debugging are enabled on your phone.
Connect your phone to your development machine via USB.
In Android Studio, click Run. Select your device as the deployment target and click OK.
The sample app launches on your phone and ARCore starts detecting planes in front of your camera.
Once planes are detected, tap your phone screen to place an anchor on a plane.
Tap the HOST button to host the anchor.
A host request is sent to the Google ARCore Cloud Anchor API. This request includes visual features and IMU readings representing the anchor's position. Once the anchor is hosted, it is assigned an ID that is used for resolving Cloud Anchors in this space.
The app displays a room code after the hosting request succeeds. You can use the code to access previously hosted anchors for this room, using the same device or another device.
Tap RESOLVE and enter a previously returned room code to access hosted anchors for this room.
A resolve request is sent to the Google ARCore Cloud Anchor API, returning the IDs of anchors currently hosted in the room. The sample app uses these IDs to render 3D objects attached to the hosted anchors.