Skip to main content

Handling Location Permission Request

This feature is only applicable when using CriteriaBasedMapSelection.

When using CriteriaBasedMapSelection, it is necessary to get your current device's GPS location so the SDK will request location permission usage. The user might grant or deny this permission, so as a developer you need to handle these cases.

// ARSharedAnchorManager.cs

public delegate void RequestPermissionEvent();

// Attach a callback to this event to listen for when the user denies location usage.
// If the user chooses to deny and not ask anymore, this callback will be called everytime
// criteria-based map selection is run
public event RequestPermissionEvent OnLocationPermissionDenied;

// Attach a callback to this event to listen for when the user grants location usage.
public event RequestPermissionEvent OnLocationPermissionGranted;

Usage Example

[SerializeField]
private ARSharedAnchorManager _sharedAnchorManager;

private void OnEnable()
{
// Subscribe to events
_sharedAnchorManager.OnLocationPermissionGranted += ShowRelocalizingUI;
_sharedAnchorManager.OnLocationPermissionDenied += ShowDeniedPermissionUI;
}

private void OnDisable()
{
// Unsubscribe to events
_sharedAnchorManager.OnLocationPermissionGranted -= ShowRelocalizingUI;
_sharedAnchorManager.OnLocationPermissionDenied -= ShowDeniedPermissionUI;
}

private void ShowRelocalizingUI()
{
// Enable UI for showing relocalizing state e.g.,
// _relocalizingUI.SetActive(true);
}

private void ShowDeniedPermissionUI()
{
// Enable UI for showing denied location permission state e.g.,
// _deniedPermissionUI.SetActive(true);
}