The Spreadsheet You Can’t Switch Off
- File size: 742.88 KB
ARCore-Location, our open source Android library for putting AR content at a real latitude and longitude, has reached 2.0. It’s a rewrite. Markers stay put when you tilt the phone, the library switches to ARCore’s Geospatial API when your app has it turned on, and the core now works with any renderer instead of only Sceneform. MIT licensed, on GitHub.
We first wrote about ARCore-Location in March 2018. Apple’s ARKit already had community projects for placing objects at GPS coordinates, and ARCore on Android had nothing equivalent, so we wrote one. Other developers picked it up and sent fixes over the next couple of years.
That article ended on a problem we hadn’t solved. A phone’s compass is only accurate to about 15 degrees, which is fine for a map and not fine when you’re trying to put a label over a building across the road. We asked for ideas. The best 1.x could offer was a manual nudge: tap the edge of the screen to rotate north a degree at a time until things lined up.
Then Google archived Sceneform, the 3D renderer the library was built on, and from 2020 the repository mostly sat still.
Version 1.x took the latest GPS fix and compass heading and re-anchored every marker from them every five seconds. Each noisy reading moved everything, and because the heading came from the phone’s orientation, tilting the phone could swing the markers too.
2.0 keeps every GPS and compass reading. It pairs each one with where ARCore’s motion tracking says the camera was at that moment, then combines all of them, weighted by the accuracy each one reports. From that it estimates two things: which direction in the AR scene is north, and where on earth the scene started. Markers are placed in ARCore’s own gravity-aligned space, so tilting the phone doesn’t move them. They get steadier the longer a session runs, and one bad GPS fix barely shifts them. The library also corrects for magnetic declination, the gap between magnetic north and true north, which 1.x left to you.
Markers are only re-anchored when their estimated position actually moves, they can have a real altitude, and when several overlap you can stack them or hide the extras.
In 2022 Google added the Geospatial API to ARCore. It works out where the phone is and which way it’s facing by matching the camera image against Street View imagery, and it’s accurate to a few metres and a few degrees. That’s a better answer to the question we asked in 2018 than anything we could do with the compass.
If your app’s ARCore session has Geospatial mode enabled, ARCore-Location uses it automatically and falls back to GPS and compass whenever it isn’t available. You need an ARCore API key from Google Cloud for it; without one, the library carries on with GPS and compass. We’d recommend it for anything where precision matters, because GPS and compass alone still leave markers within a few tens of metres of you noticeably off.
2.0 comes as two modules. arcore-location is the core: it turns coordinates into positions in an ARCore scene and depends only on ARCore and Google Play services, so you can draw the results with whatever renderer you like. arcore-location-sceneform keeps the familiar LocationScene and LocationMarker for apps that already use Sceneform.
The Sceneform module has a catch. It uses the community fork of Sceneform, which was itself archived in 2024, and its native libraries aren’t aligned for 16 KB memory pages. Google Play won’t accept apps that target Android 15 or later and include them. The module is there so existing 1.x apps can upgrade without rewriting their rendering. If you’re starting a new app, use the core module with a maintained renderer such as SceneView.
Most of the API has changed, and there’s one change that compiles without complaint: LocationMarker now takes latitude before longitude. Swap them by accident and your marker ends up somewhere else entirely. Read the migration guide before you start. 2.0 needs AndroidX, Java 17 and a minSdk of 24.
Add JitPack to your repositories, then add one of the modules:
implementation("com.github.appoly.ARCore-Location:arcore-location:2.0.0")
implementation("com.github.appoly.ARCore-Location:arcore-location-sceneform:2.0.0")
The source is on GitHub under the MIT licence, with an example app and the full changelog. It’s provided as-is, and issues and pull requests are welcome. If you’re planning a location-based AR app and would rather not build it yourself, get in touch.