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 a sample app
This guide assumes that you have already installed and configured the ARCore SDK for Android. If not, see the Quickstart for Android for installation and setup steps.
If you are new to working with anchors, see Working with Anchors for an introduction.
To use cloud anchors, you'll need:
A USB cable to connect your phone to your development machine
Android Studio version 3.0 or later with Android SDK Platform version 7.0 (API level 24) or higher.
The ARCore SDK for Android. To get the SDK, you can do either of the following:
Download the ARCore SDK for Android and extract it.
Clone the repository with the following command:
git clone https://github.com/google-ar/arcore-android-sdk.git
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 Anchors 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 Anchors API key to your project. To do this:
Try out the sample app
Build and run the
helloarcloudanchor sample app to try out hosting and resolving
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 Cloud Anchor service. The host request includes data representing the anchor's position relative to the visual features near it. A successful host request establishes a cloud anchor here and assigns it a cloud anchor ID.
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 Anchors 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.
Start using cloud anchors in your own apps. To learn more, see: