Magnetic Declination Flutter Plugin

The magnetic_declination plugin provides a method to calculate the magnetic declination for a given location and time. This plugin supports Android and iOS platforms and integrates seamlessly with Flutter applications.

Features

  • Calculate the magnetic declination based on:
    • Latitude
    • Longitude
    • Altitude
    • Specific date and time
  • Cross-platform support (Android and iOS).

Installation

Add the package to your Flutter project by including it in your pubspec.yaml:

dependencies:
  magnetic_declination:

Run the following command to install the package:

flutter pub get

example

import 'package:magnetic_declination/magnetic_declination.dart';

void main() async {
  double latitude = 37.7749;
  double longitude = -122.4194;
  double altitude = 30.0; // in meters
  DateTime date = DateTime.now();

  double declination = await MagneticDeclination.calculateDeclination(
    latitude,
    longitude,
    altitude,
    date,
  );

  print('Magnetic Declination: $declination');
}

Platform-specific Implementations

Android

The plugin uses the GeomagneticField class from the Android SDK to compute the declination. The calculation is based on the location and time passed from the Dart code.

iOS

On iOS, the plugin leverages the CoreLocation framework to access location-based services for declination calculations.

Methods

calculateDeclination

Parameters:

  • latitude (double): Latitude in decimal degrees.
  • longitude (double): Longitude in decimal degrees.
  • altitude (double): Altitude in meters.
  • date (DateTime): Date and time for which the declination is calculated.

Returns:

  • Future<double>: The calculated magnetic declination in degrees.

Error Handling

If an error occurs during the calculation, the method returns 0.0 and logs the error. Check your logs for detailed error messages to debug issues.

Contributing

Contributions are welcome! Feel free to submit pull requests or open issues on the repository.

License

This project is licensed under the GNU Lesser General Public License v3.0.

Maintainer

Developed and maintained by Ali Miracle.
Email: alimiracle@riseup.net