public final class RangingUpdate
- Object
- RangingUpdate
One measurement of where the peer is, delivered to
RangingListener.updated on the EDT.
Every field except the timestamp is optional, and they drop out
independently: a peer directly behind the phone commonly reports a
distance with no direction, and a peer at the edge of range reports
neither. Guard each read with its has method rather than assuming a
sentinel value.
public void updated(RangingUpdate u) {
if (u.hasDistance()) {
label.setText(String.format("%.1f m", u.getDistance(RangingUnit.METERS)));
}
if (u.hasDirection()) {
arrow.setAngle(u.getAzimuth());
}
}
Constructors
public RangingUpdate(boolean hasDistance, double distanceMeters, boolean hasDirection, double azimuth, boolean hasElevation, double elevation, float[] vector, long timestamp) | Ports construct these; application code receives them through RangingListener. |
Methods
public boolean hasDistance() | true when this update carries a distance measurement. |
public double getDistance(RangingUnit unit) | The straight-line distance to the peer, in the unit you name. |
public boolean hasDirection() | true when this update carries a horizontal direction. |
public double getAzimuth() | The horizontal angle to the peer in degrees. |
public boolean hasElevation() | true when this update carries a vertical direction. |
public double getElevation() | The vertical angle to the peer in degrees, in the range -90 to 90, where positive is above the device. |
public float[] getDirectionVector() | The platform’s raw unit direction vector as {x, y, z} – x to the right, y up, z toward the user, so the forward direction is negative z. iOS only; null everywhere else and null on iOS whenever hasDirection() is false. |
public long getTimestamp() | System.currentTimeMillis() at the moment the port received this measurement. |
public String toString() | Returns a string representation of the object. |
Inherited methods
Constructor details
RangingUpdate
public RangingUpdate(boolean hasDistance, double distanceMeters, boolean hasDirection, double azimuth, boolean hasElevation, double elevation, float[] vector, long timestamp)RangingListener.Parameters
hasDistanceboolean- whether this update carries a distance
distanceMetersdouble- the distance in meters, ignored when
hasDistanceis false hasDirectionboolean- whether this update carries an azimuth
azimuthdouble- horizontal angle in degrees, ignored when
hasDirectionis false hasElevationboolean- whether this update carries an elevation
elevationdouble- vertical angle in degrees, ignored when
hasElevationis false vectorfloat[]- the platform’s raw unit direction vector, or
null timestamplongSystem.currentTimeMillis()when the port received the measurement
Method details
hasDistance
public boolean hasDistance()true when this update carries a distance measurement.getDistance
public double getDistance(RangingUnit unit)The straight-line distance to the peer, in the unit you name.
Undefined when hasDistance() is false – check first. There is
no zero-argument form on purpose; see RangingUnit.
Parameters
unitRangingUnit- the unit to read the distance in
Returns
unithasDirection
public boolean hasDirection()true when this update carries a horizontal direction.getAzimuth
public double getAzimuth()The horizontal angle to the peer in degrees. Zero is straight ahead – out of the top of a phone held upright – and positive is to the right.
Undefined when hasDirection() is false.
The range is platform-dependent, and the difference is meaningful.
Apple reports a unit direction vector, which the port folds with
atan2(x, -z) into -180 to 180 – so it distinguishes a peer in front
from one directly behind. Jetpack UWB reports the angle itself, in
degrees, but only over -90 to 90, which does not. Code that needs to
know which side of the device a peer is on cannot get that from
azimuth alone on Android.
getDirectionVector() still hands back Apple’s untouched vector for
code that wants it.
hasElevation
public boolean hasElevation()true when this update carries a vertical direction.getElevation
public double getElevation()The vertical angle to the peer in degrees, in the range -90 to 90, where positive is above the device.
Undefined when hasElevation() is false. Fewer devices report
elevation than azimuth, so this drops out on its own.
getDirectionVector
public float[] getDirectionVector()The platform’s raw unit direction vector as {x, y, z} – x to the
right, y up, z toward the user, so the forward direction is negative
z. iOS only; null everywhere else and null on iOS whenever
hasDirection() is false.
Prefer getAzimuth() and getElevation(), which are derived from
this on iOS and reported natively on Android, so they work on both.
A fresh copy is returned each call.
getTimestamp
public long getTimestamp()System.currentTimeMillis() at the moment the port received this
measurement. The platforms disagree on what clock their own
timestamps use – Android reports elapsed realtime nanoseconds and
iOS reports nothing at all – so this is stamped on arrival rather
than translated, and is comparable only with other values from this
same clock.toString
public String toString()