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.
Requirements
To use Cloud Anchors, you'll need:
Hardware
An ARCore-supported phone, installed with the latest version of Google Play Services for AR
A USB cable to connect your phone to your development machine
Software
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
The helloarcloudanchor
sample app is included with the ARCore SDK for Android.
In Android Studio, you can find it under:
app/java/com.google.ar.core.examples.java
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.json
file generated as part of adding Firebase to your app. - In Android Studio, add the
google-services.json
file to your project's module folder. Typically, this is theapp/
folder.
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 a
<meta-data>
element:<meta-data android:name="com.google.android.ar.API_KEY" android:value="<YOUR_API_KEY>"/>
- Add the
<meta-data>
element to the<application>
element inapp/manifests/AndroidManifest.xml
.
- Add the
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 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 Anchors here and assigns it a Cloud Anchors 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 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.
Next steps
Start using Cloud Anchors in your own apps. To learn more, see: