Configure your app's settings so that it can use the Geospatial API.
Prerequisites
Make sure that you understand fundamental AR concepts and how to configure an ARCore session before proceeding.
Sample app and codelab
This video walks through the steps to building an app that displays Geospatial data and places content in real-world locations using the Geospatial API.
You can also follow the Geospatial codelab documentation for the same steps. To run the sample app created in the video, see the ARCore Geospatial Quickstart.
See the Introduction to the Geospatial API for more information about the Geospatial API.
If you're new to developing with ARCore, see Getting started for information about software and hardware requirements, prerequisities and other information specific to the platforms you are using.
Be sure your development environment satisfies the ARCore SDK requirements, as described in the Quickstart.
Enable the ARCore API
Before using the Visual Positioning System (VPS) in your app, you must first enable the ARCore API in a new or existing Google Cloud project. This service is responsible for hosting, storing, and resolving Geospatial anchors.
Keyless authorization is preferred, but API Key authorization is also supported.
Add required libraries to your app
After authorizing your app to call the ARCore API, you must add libraries to enable Geospatial features in your app.
In your app's build.gradle
file, setup Google Play services to include the Play
Services Location library.
dependencies {
// Apps must declare play-services-location version >= 16.
// In the following line, substitute `16 (or later)` with the latest version.
implementation 'com.google.android.gms:play-services-location:16 (or later)'
}
Enable Geospatial capabilities in the session configuration
Before creating the session, change the GeospatialMode
in your session
configuration to ENABLED
:
Java
Config config = session.getConfig(); config.setGeospatialMode(Config.GeospatialMode.ENABLED); session.configure(config);
Kotlin
// Enable the Geospatial API. session.configure(session.config.apply { geospatialMode = Config.GeospatialMode.ENABLED })
While the Geospatial mode is set to ENABLED
, the application is allowed to obtain
geographical information from the Visual Positioning System (VPS).
Prompt user to allow usage of device data
Apps that use the ARCore Geospatial API must present the user with a prompt to acknowledge and allow the use of data from their device. See User privacy requirements for more information.
Check device compatibility
Not all devices that support ARCore also support the Geospatial API, as described in the quickstart.
To check the user's device for compatibility, call
Session.checkGeospatialModeSupported()
.
If this returns false do not attempt to configure the session (below), as doing
so will throw an
UnsupportedConfigurationException
.
Ask user for location permissions at runtime
Your app must request location permissions at runtime.
To use the ARCore Geospatial API, your app needs to register the following extra permissions:
ACCESS_FINE_LOCATION
to accurately determine the user's location.ACCESS_COARSE_LOCATION
for non-accurate determination of the user's location and to comply with user privacy requirements. However, the Geospatial API cannot be configured to work with coarse location, and API requests will fail when the user has set this permission. See below for more information.ACCESS_INTERNET
to contact the ARCore Geospatial API service.
<manifest ... >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
On devices that run Android version 12 or higher,
users can request
that your app have access to only
approximate location
information. To accommodate this request, your app must have the
ACCESS_COARSE_LOCATION
permission configured, along with
ACCESS_FINE_LOCATION
,
as shown above. You must
configure both location permissions.
However, when users specify coarse location, doing so prevents the Geospatial API from obtaining the precise location it requires. The Geospatial service will not allow itself to be configured if your app gives it only coarse location. Your app cannot use the Geospatial API with coarse location.
Check Geospatial availability at the device's current location
Because the Geospatial API uses a combination of VPS and GPS to determine a Geospatial pose, the API can be used as long as the device is able to determine its location. In areas with low GPS accuracy, such as indoor spaces and dense urban environments, the API will rely on VPS coverage to generate high accuracy poses. Under typical conditions, VPS can be expected to provide positional accuracy of approximately 5 meters, and rotational accuracy of 5 degrees. Use Session.checkVpsAvailabilityAsync()
to determine if a given location has VPS coverage.
The Geospatial API can also be used in areas that do not have VPS coverage. In outdoor environments with few or no overhead obstructions, GPS may be sufficient to generate a pose with high accuracy.
What's next
- Obtain the device camera's Geospatial pose to determine the exact location of the user's device in the real world.
- Check VPS availability at a device's given location.