addGeoAnchor method

Future<UArAnchor> addGeoAnchor({
  1. required double latitude,
  2. required double longitude,
  3. double altitude = 0,
  4. UArAltitudeMode altitudeMode = UArAltitudeMode.terrain,
  5. double heading = 0,
  6. String? id,
})

Pins an anchor to a real-world coordinate. Uses visual positioning when the device and location support it, else GPS + compass.

Implementation

Future<UArAnchor> addGeoAnchor({
  required double latitude,
  required double longitude,
  double altitude = 0,
  UArAltitudeMode altitudeMode = UArAltitudeMode.terrain,
  double heading = 0,
  String? id,
}) async {
  final String anchorId = id ?? newId("g");
  if (_useVps) {
    try {
      final Map<Object?, Object?>? raw = await _invoke<Map<Object?, Object?>>("addGeoAnchor", <String, Object?>{
        "id": anchorId,
        "latitude": latitude,
        "longitude": longitude,
        "altitude": altitude,
        "altitudeMode": altitudeMode.name,
        "heading": heading,
      });
      if (raw != null) {
        final UArAnchor anchor = UArAnchor.fromMap(raw);
        value = value.copyWith(anchors: <String, UArAnchor>{...value.anchors, anchor.id: anchor});
        return anchor;
      }
    } on UArException {
      if (config.geoMode == UArGeoMode.vps) rethrow;
    }
  }
  final _GpsAnchor target = _GpsAnchor(latitude: latitude, longitude: longitude, altitude: altitude, altitudeMode: altitudeMode, heading: heading);
  _gpsAnchors[anchorId] = target;
  await startLocationUpdates();
  return addAnchor(_gpsPose(target), id: anchorId, name: "geo");
}