Skip to main content

Getting Geolocation with WPS

Prerequisites

This guide assumes that you’ve already gone through:

  • How to set up a basic AR session guide.
  • Getting started with WPS guide.

Accessing Geolocation Estimates

Adding the ARWorldPositioningManager to the XROrigin component in the Hierarchy will automatically add an ARWorldPositioningCameraHelper to the Main Camera. To directly access the more accurate compass and GPS properties provided by WPS, the values are directly exposed through the CameraHelper. A sample script accessing these values can be found below:

Click to reveal WPSCompass.cs
Attention!

Be sure to set the ARCameraManager in the XROrigin inspector before running!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Niantic.Lightship.AR.WorldPositioning;
using UnityEngine.XR.ARFoundation;

public class WPSCompass : MonoBehaviour
{
[SerializeField] private ARCameraManager _arCameraManager;

private ARWorldPositioningCameraHelper _WPSCameraHelper;

// Start is called before the first frame update
void Start()
{
_WPSCameraHelper = _arCameraManager.GetComponent<ARWorldPositioningCameraHelper>();
}

// Update is called once per frame
void Update()
{
float heading = _WPSCameraHelper.TrueHeading;

double latitude = _WPSCameraHelper.Latitude;
double longitude = _WPSCameraHelper.Longitude;
double altitude = _WPSCameraHelper.Altitude;

Quaternion q = _WPSCameraHelper.RotationCameraRUFToWorldEUN;
}
}

The Latitude, Longitude, Altitude, and TrueHeading fields provide the estimated geolocation for the device, where TrueHeading represents the heading relative to true north. the RotationCameraRUFToWorldEUN provides the quaternion for the device's orientation in East-Up-North space (where East is +x axis, Up is +y axis, and North is +z axis).