Using Location based AR in your next game or application.

Ekansh Mittal
7 min readJul 16, 2024

--

Hello Folks 🙋‍♂️,
I am an AR Evangelist and have been exploring this field for quite some time. Recently, I got the chance to work on Geo-Location based AR. This is the first time I got a chance to work on it and integrate them with the server. It was an amazing experience and I was blown away by the possibilities it brings to the table for the developers who are building any game or app.

I was really excited to deep dive into this and figure out how it works, and well it was a rollercoaster ride filled with its ups and downs but in the end, the journey was amazing and fruitful in all essence.

Through this blog, I will be sharing how we can setup and create a Geo-Location AR Scene in Unity.

Let’s first understand what is Geo-Location based AR application means and what are certain use cases of this and then we will be deep diving into how we can setup the Location based AR Scene in Unity.

What is Geo-Location AR and how it works?
Geo-Location based augmented reality utilizes GPS to overlay digitally created and modeled information onto the real world without physical markers. It is also known as marker less or location-based AR. It relies on RTLS (real-time location systems). The role of these RTLS technologies is to get location data from sensors in smartphones and other devices to pinpoint the user’s current location. By comparing the user’s coordinates against points of interest in the database, the technology can accurately overlay the virtual elements at relevant real-world positions, which helps in overlaying the digital models onto the physical world.

So, now we get a basic idea of what is geo-spatial AR and how it works. let’s take a closer look at how to setup your own project?

We will be creating a general project to setup geo-location AR. Let’s cut the chit-chat and get started with it.

Steps To Complete

  1. Project Setup
  • Creating a new Unity Project in 2022.3.x.
  • Creating a basic scene in Unity.

2. Working on setting up geo-spatial pipeline

  • Importing zip files to Unity
  • Setting up GCP
  • Setting up Unity and connecting with APIs
  • Rendering the geo-spatial world based on latitude and longitude.
  • Adding a 3D Cube to the world.

Project Setup

In this part, we will be creating a new Unity project and setting the basics required for getting the geo-spatial project running.

Creating a new Unity Project

Simply create a new project in Unity (use Unity 2022.3.x) with a URP Template and name it whatever you want to, I will be naming it “Geo-Spatial Demo”.

Create a new project named Geo-Spatial Demo

Now that our newly created project has been initialized, let me change the layout of my editor to “Tall” because that is how I like it.
A quick suggestion from my side to all the Unity beginners to change your Unity Layout to “Tall” if you are a beginner in Unity so that you can follow my steps easily.

Let us also create a good folder structure so that things don’t get messy afterward. We will make a folder named “0_Project” which will contain all the scenes, scripts, prefabs, etc. created by us.

Creating a clean folder structure

Switching the platform to Android

Before we deep dive into the codebase and start importing various libraries, I would personally prefer to switch my platform to Android.

Switching Platform to Android

The first part of the blog is done 😎

Downloading dependencies/packages:

Step #1:
Go to this link and download arcore-unity-extensions-1.44.0.tgz and keep it somewhere in your system, we will be using it later.

Download ARCore Extensions

Step #2:
Go to this link and download com.cesium.unity-1.3.0.tgz and keep it somewhere in your system, we will be using it later.

Downloading Cesium 1.3.0

Importing these dependencies to Unity:

Step #1:
Go to the “Window” tab and then click on “Package Manager”.
On the “Package Manager” Window, Click on the “+” icon in the top left and select “Add package from tarball…” and click on ARCore Extensions folder we downloaded.
You might need to RESTART your project as ARCore Extensions uses New Input System, just click on Yes and it will automatically do the task for you!

Importing ARCore Extensions

Step #2:
Go to the “Window” tab and then click on “Package Manager”.
On the “Package Manager” Window, Click on the “+” icon in the top left and select “Add package from tarball…” and click on Cesium folder we downloaded just before.

Importing Cesium Package

Step #3:
Go to ARCore Extension Packages and click on “Samples” and install “Geospatial Sample”.

Installing Geo-Spatial Sample from ARCore Extensions

Done with the dependencies, yay!! 🥳

Step #4:
Go to Player Settings and let’s tweak the changes like,
- Deselect Auto Graphics API
- Remove Vulkan Graphics API
- Make the Minimum API Level to around 9.0
- Change the Scripting Backend to IL2CPP
- Change ARMv6 to ARMv64

Tweaking the Player Settings

Step #5:
Now, Go to XR Plugin Management and Select ARCore.
Then, Go to ARCore Extensions and select Geo-Spatial checkboxes as shown below.

Tweaking XR Plugin Management

Let’s work with Google Cloud Platform now, and the fun begins!!

Step #1:
So, First we need to setup the GCP, you can go to this link and create a project.
You might need to add your credit card details, rest assured it will only charge you for the calls that exceed a basic limit.
Once setup with this, we can move forward.

Step #2:
Click on Console and then click on API & Services.

Console Page of GCP

Step #3:
Search and Activate a bunch of APIs which we will be using for Geo-Location.
- ARCore API
- Map Tiles API

ARCore API
Map Tiles API

Step #4:
Once the APIs are enabled, now we need to create our API key, so hover over API & Services and then click on Credentials.

Create our own API Key

Step #5:
Once the API key is created, you can go into the API details and copy the API key from here.

Copy API Key

Final Showdown!
We are finally at the last bit of steps before completing the project, if you followed along till here, just stay a bit more and let’s achieve the desired result we have been waiting for…

Step #1:
Go back to Unity, and open Project Settings, ARCore Extensions and paste the API Key.

Step #2:
Open Geo-Spatial Sample Scene from the Geo-Spatial folder.

Step #3:
To create Geo-Spatial experiences, you need to add “AR Geospatial Creator Origin” object by following this below gif.

Adding AR Geospatial Creator Origin GameObject

Step #4:
Click on “Add Cesium Georeference Component” and add Map Tiles API key into the field.

And that’s almost done!
You can test by searching some latitude and longitude and you will see 3D location being spawned in your Scene tab.
So, its like having Google Earth inside Unity3D and it has a lot more use cases than just using it for this purpose.

Rendering Google Earth in Unity

Adding a 3d object to a particular location
Add a 3D Object and add “AR Geospatial Creator Anchor” script and add it to the desired position in the world, where you want to see it.

Adding Cube to Geo location

And we are done!
If you are able to follow along till here, just build your Unity Project with your latitude, longitude and you will be able to experience Geo-Location based AR.

Ending Notes

At the end of this blog, I hope you got to learn a thing or two. I would really appreciate if you guys could share what you have created with this tutorial.

Feel free to connect with me on LinkedIn.

Kudos to everybody

-Yaugan
(Ekansh Mittal)
XR Enthusiast

--

--

Ekansh Mittal

An introvert person, starting writing about simple topics which affect many people around us. Always up for improvements and suggestions.