Skip to main content

Components List

This section gives a high level overview of the package. More detail can be found below in the API Reference section.

Core

The NavigationDataComponent holds a list of Places and provides APIs to select a Place for navigation, and fires useful events such as onArrivedAtPlace. Other components in this kit subscribe to events on NavigationDataComponent.

Place

A Place represents a navigable location and comprises information such as name, description, and icon. The following specialised location types derive from the Place class:

  • GeoLocationPlace: A place that gets its position from a geoposition.
  • CustomLocationPlace: A place that gets its position from a LocatedAtComponent representing a Custom Location created on Spectacles. The Custom Location's geoposition is used for navigation and is refined by successful location tracking if possible.
  • SceneObjectPlace: A place defined only in virtual space, without an associated physical location.

UserPosition and EditableUserPosition

EditableUserPosition implements the UserPosition interface and represents the user's position in both virtual and geo spaces. APIs are provided to get distance and bearing relative to a Place.

Assets

The package contains two ready-to-use assets, a menu and a 3D navigation arrow:

  • The menu asset can be found inside the Navigation Kit prefab, which in turn can be found in the package root. Dragging this prefab into the scene will also add the menu.
  • Adding the ARNavigationPrefab [PUT_IN_SCENE] prefab to your Scene will add a 3D arrow that will point to the currently selected Place. You will find this in the ARNavigationComponent folder.

Together these form a working example of how to use the kit.

Scripts

The above assets are controlled by these scripts:

ExampleMenu

This contains a simple example of how to read Places from the NavigationDataComponent, and how to select a Place to which to navigate.

ARNavigation

Controls the 3D arrow used to guide the user. This script also contains examples demonstrating how to subscribe to events from the NavigationDataComponent, and examples demonstrating the use of the orientation and distance functions.

API Reference

This section details the functions and properties of the main scripts provided in the kit.

Handles the navigation location data and tracking logic which can be used to generate a guided experience. From this component you can add navigable places and select the place to which to navigate. The component also exposes a number of callbacks, which are triggered when the user approaches the selected destination, reaches the destination, and leaves the destination. Callbacks are also triggered when all places from the guided experience have been visited. The component automatically switches between tracking technologies to make sure the best available technology is used.

SignatureTypeDescription
METHODS
addPlacefunction (place: Place) → voidAdds a new place of interest to the guided experience.
removePlacefunction (place: Place) → voidRemoves the provided location from the guided experience.
getUserPositionfunction () → UserPositionRetrieves the users position for navigation purposes.
navigateToPlacefunction (place: Place) → voidSelects a location to provide directions towards and triggers the tracking logic to navigate to the selected location.
stopNavigationfunction () → voidRemoves the current selected location for navigation purposes and stops any tracking attached to it if necessary.
PROPERTIES
statusNavigationStatusRepresents the status of the navigation component.
arrivalRadiusnumberRadius in meters to determine if the user has reached the selected destination.
placesPlace[]The list of registered places.
EVENTS
onNavigationStartedPublicApi<Place>Triggered when navigation has been started.
onPlacesUpdatedPublicApi<void>Triggered when the list of places has been changed.
onArrivedAtPlacePublicApi<Place>Triggered when a place has been reached.
onAllPlacesVisitedPublicApi<void>Triggered when all places have been visited.

Example Code

@input navigationComponent: NavigationDataComponent

/*
* Called from a menu of Places that can be selected as the active tracked.
*/
public navigationLocationSelected(place: Place): void
{
this.navigationModule.navigateToPlace(place)
}

/*
* Selects the nearest Place to be tracked.
*/
public selectNearest(): void
{
const nearestPlace = this.navigationComponent.places
.sort(/*lowest distance*/)
.first()
this.navigationComponent.navigateToLocation(nearestPlace)
}

/*
* Subscribed to navigationComponent.onNavigationStarted to update menus
*/
public onNavigationLocationSelected(place: Place): void
{
this.myMenuImage.image = place.icon
this.myMenuTitle.text = place.name
}

An enumeration of supported statuses in the navigation component.

NameDescription
LocationNotSelectedNo place to navigate to has yet been provided. Use the navigateToPlace(place: Place) function to select one.
InitializingThe resources for the relevant tracking technology are being initialized.
InProgressNavigation directions towards the selected location are being computed as expected. The user is expected to be following directions.
SucceededNavigation directions were provided and the user successfully reached the destination.

Place

A place of interest or physical location in the world that can be navigated to, e.g. a geo-location or Custom Location.

SignatureTypeDescription
METHODS
getRelativePositionfunction () → vec3 | nullReturns the relative position of this location with respect to the initial position of the user when the session started. This position is not geo-referenced in the Earth’s global coordinate frame and its reference frame corresponds with the world reference frame set by DeviceTracking component when choosing ‘World’. Returns null when using geo-referenced navigation locations and the geo-referenced user position is not available.
getGeoPositionfunction () → GeoPosition | nullReturns the geo-referenced position of this location in the world, represented using the GeoPosition data structure. Contains latitude, longitude and altitude among other data.
requestNewGeoPositionfunction () → booleanRequests an update to the geo-referenced position of this place. Returns true if accepted, false if rejected.
getOrientationfunction () → quatReturns the orientation of the location represented as a quaternion.
PROPERTIES
namestringThe name of the place.
iconTextureAn icon representing this location.
descriptionstringA description of the place.
visitedbooleanTrue if the user has gone to this place in this session.
readybooleanTrue if the place has been initialized and content is ready for arrival.
EVENTS
onStatusUpdatedPublicApi<void>Triggers when the internal status has changed.

UserPosition

Represents the position of the user in both world and geo space. Updates when new data is received.

SignatureTypeDescription
METHODS
initializeGeoLocationUpdatesfunction (accuracy: GeoLocationAccuracy, updateFrequency: number)) → voidInitializes the user position for use, taking the accuracy to be used and the time between refreshes of the users position.
getGeoPositionfunction () → GeoPosition | nullThe position of the user in Geo Space.
getNorthAlignedOrientationfunction () → quatReturns a quaternion representing the north aligned orientation of the user.
getBearingfunction () → numberReturns the users north aligned orientation in radians. Indicates how far off from heading north the device is. Zero represents true north, and the direction is determined clockwise.
getRelativeTransformfunction () → TransformReturns the relative position and orientation of the user with respect to the initial position of the user when the session started.
getDistanceTofunction (location: Place) → number | nullReturns the distance, in meters, from the user to the provided navigation location. Null if it can't be calculated.
getBearingTofunction (location: Place, world: boolean) → number | nullReturns the bearing, in radians, from the current user position to the navigation target location. If world is true the users bearing will not be taken into account.
PROPERTIES
statusUserPositionStatusReturns the status of the internal location, for use with debugging potentially hidden code.
gpsActivebooleanReturns true if GPS is active.
EVENTS
onUserPositionUpdatedPublicApi<void>Called when the position has been updated.

Example Code

  /**
* Calculates the distance between the user and a given `GeoLocation`.
*/
private getPhysicalDistance(userPosition: UserPosition): number | null {
const userGeoPosition = userPosition.getGeoPosition()
if (isNull(userGeoPosition)) {
return null
}
return getPhysicalDistanceBetweenLocations(userGeoPosition, this.getGeoPosition())
}


/**
* Called whenever the user position is updated to update the target rotation of a scene object pointing the way.
*/
private onUserPositionUpdated(): void {
const angle = this.userPosition.getBearingTo(this.selectedPlace, true)
this.targetRotation = quat.angleAxis(-angle, vec3.up())
}

UserPositionStatus

Represents the positioning status, good for debugging potentially inaccurate or missing location data.

NameDescription
UnknownUser position can not be determined.
UnknownErrorNetworkMissingPosition unknown as could not connect to any network.
UnknownPoorGPSReceptionPosition unknown due to poor GPS.
GeoLocalizationAvailableWorking and available.
GlobalLocalizationPoorGPSReceptionLocation found, but inaccurate.
ErrorTrackingAssetFailedToDownloadCould not download the necessary assets.
Was this page helpful?
Yes
No