Interface MagnetometerService

All Known Implementing Classes:
AndroidMagnetometerService, DummyMagnetometerService, IOSMagnetometerService, MobileMagnetometerService

public interface MagnetometerService
A magnetometer measures the ambient geomagnetic field for all three physical axes (x, y and z).

The service gets started by calling either start() or start(Parameters), and can be stopped at any time by calling stop().

The MagnetometerService provides a read-only reading property that is updated at regular intervals by the underlying platform implementation. A user of the MagnetometerService can listen to changes of the magnetic field, by registering a ChangeListener to the reading property.

Example

 MagnetometerService.create().ifPresent(service -> {
      service.start();
      MagnetometerReading reading = service.getReading();
      System.out.printf("Magnetic field: %.4f, %.4f, %.4f. Magnitude: %.4f",
              reading.getX(), reading.getY(), reading.getZ(), reading.getMagnitude());
  });

Android Configuration: none

iOS Configuration: none

Since:
3.0.0
  • Property Details

    • reading

      javafx.beans.property.ReadOnlyObjectProperty<MagnetometerReading> readingProperty
      A frequently-updated reading from the magnetometer.
      See Also:
  • Field Details

    • DEFAULT_PARAMETERS

      static final Parameters DEFAULT_PARAMETERS
      Default frequency is 10 Hz (10 samples per second).
  • Method Details

    • create

      static Optional<MagnetometerService> create()
      Returns an instance of MagnetometerService.
      Returns:
      An instance of MagnetometerService.
    • getReading

      MagnetometerReading getReading()
      Returns a single reading from the magnetometer.
      Returns:
      the current magnetometer reading
    • readingProperty

      javafx.beans.property.ReadOnlyObjectProperty<MagnetometerReading> readingProperty()
      A frequently-updated reading from the magnetometer.
      See Also:
    • start

      void start()
      Starts the service with DEFAULT_PARAMETERS.
      Since:
      4.0.10
    • start

      void start(Parameters parameters)
      Starts the service with given parameters.
      Parameters:
      parameters - Parameters for configuring the service
      Since:
      4.0.10
    • stop

      void stop()
      Stops the service.
      Since:
      4.0.10