Skip to main content

XR8.Vps.makeWayspotWatcher()

XR8.Vps.makeWayspotWatcher({onVisible, onHidden, pollGps, lat, lng})

Description

Create a watcher to look for all VPS activated Wayspots, not just Project Wayspots.

Parameters

ParameterDescription
onVisible [Optional]Callback that is called when a new Wayspot becomes visible within a 1000 meter radius.
onHidden [Optional]Callback that is called when a Wayspot you previously saw is no longer within a 1000 meter radius from you.
pollGps [Optional]If true, turns on GPS and calls ‘onVisible’ and ‘onHidden’ callbacks with any wayspots found/lost through GPS movement.
lat [Optional]If lat or lng is set, calls onVisible and onHidden callbacks with any wayspots found/lost near the set location.
lng [Optional]If lat or lng is set, calls onVisible and onHidden callbacks with any wayspots found/lost near the set location.

Returns

An object with the following methods:

{dispose(), pollGps(), setLatLng()}

MethodDescription
dispose()Clears state and stops gps. Updates and will no longer call any callbacks.
pollGps(Boolean)Turn on or off gps updates.
setLatLng(lat: Number, lng: Number)Set the watcher's current location to lat / lng.

Example

const nearbyWayspots_ = []

// Records the time between getting each Wayspot from the wayspotWatcher.
let gotAllWayspotsTimeout_ = 0

const onWayspotVisible = (wayspot) => {
nearbyWayspots_.push(wayspot)

window.clearTimeout(gotAllWayspotsTimeout_)
gotAllWayspotsTimeout_ = window.setTimeout(() => {
// We get the wayspots individually. If want to only perform an operation
// after we have gotten all the nearby ones, we could do that here.
}, 0)
}

const onWayspotHidden = (wayspot) => {
const index = nearbyWayspots_.indexOf(wayspot)
if (index > -1) {
foundProjectWayspots_.splice(index, 1)
}
}

const onAttach = ({}) => {
wayspotWatcher_ = XR8.Vps.makeWayspotWatcher(
{onVisible: onWayspotVisible, onHidden: onWayspotHidden, pollGps: true}
)
}

const onDetach = ({}) => {
// Cleanup the watcher
wayspotWatcher_.dispose()
}