Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Compass Plugin for Flutter

License

NotificationsYou must be signed in to change notification settings

natsuk4ze/compassx

Logo

Provides reliable compass data and extensivedocumentation.

Usage

StreamBuilder<CompassXEvent>(  stream:CompassX.events,  builder: (context, snapshot) {if (!snapshot.hasData)returnconstText('No data');final compass= snapshot.data!;returnColumn(      mainAxisSize:MainAxisSize.min,      children: [Text('Heading: ${compass.heading}'),Text('Accuracy: ${compass.accuracy}'),Text('Should calibrate: ${compass.shouldCalibrate}'),Transform.rotate(          angle: compass.heading* math.pi/180,          child:Icon(Icons.arrow_upward_rounded,            size:MediaQuery.of(context).size.width-80,          ),        ),      ],    );  },),
  • heading: The heading relative to true north in degree.
  • accuracy: The accuracy of the sensor data.
  • shouldCalibrate: Whether the sensor should be calibrated or not.

Install

$flutter pub add compassx

Check the minimum supported version of your project and update as necessary.

  • iOS: 12
  • Android: 21

Request permission to get true heading in Android. Not required on iOS.

$flutter pub add permission_handler

Specify the permissions one or both of the following inAndroidManifest.xml.It can be copied fromexample.

<uses-permissionandroid:name="android.permission.ACCESS_COARSE_LOCATION" /><uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION" />
  • ACCESS_COARSE_LOCATION: Used when normal accuracy is required.
  • ACCESS_FINE_LOCATION: Used when the highest quality accuracy is required.

Add code to request permissions.

if (Platform.isAndroid)awaitPermission.location.request();

CompassXheading currently supports only portrait mode. It is recommended to fix the orientation of the device.

SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp,DeviceOrientation.portraitDown,      ]);

Testing

It is recommended to use a real device. iOS simulators cannot use the heading sensor (compass). SeeTesting CompassX for details.

Documentation

If you are going to use this plugin in your product apps, I strongly suggest you readfull documentation carefully.


[8]ページ先頭

©2009-2025 Movatter.jp