Giter VIP home page Giter VIP logo

compassx's Introduction

CompassX

Logo

Provides reliable compass data and extensive documentation.

Usage

StreamBuilder<CompassXEvent>(
  stream: CompassX.events,
  builder: (context, snapshot) {
    if (!snapshot.hasData) return const Text('No data');
    final compass = snapshot.data!;
    return Column(
      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 in AndroidManifest.xml. It can be copied from example.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android: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) await Permission.location.request();

CompassX heading 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). See Testing CompassX for details.

Documentation

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

compassx's People

Contributors

dependabot[bot] avatar natsuk4ze avatar pamafe1976 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

pamafe1976

compassx's Issues

Not working for Android SDK <29

Did you check the documentation and it did not help?

Overview

Hi,
This is a nice package and it works fine on iOS and Android >= 29.
However it should be fixed asap for Android < 29
Regards

Steps to reproduce

Just add the package to pubspec.yaml, and use minSdkVersion less than 29 in build.gradle

The moment you allow location permission you will get:


D/AndroidRuntime(11849): Shutting down VM
E/AndroidRuntime(11849): FATAL EXCEPTION: main
E/AndroidRuntime(11849): Process: com.example.testgeolocator, PID: 11849
E/AndroidRuntime(11849): java.lang.AbstractMethodError: abstract method "void android.location.LocationListener.onStatusChanged(java.lang.String, int, android.os.Bundle)"
E/AndroidRuntime(11849): 	at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:378)
E/AndroidRuntime(11849): 	at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:300)
E/AndroidRuntime(11849): 	at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:316)
E/AndroidRuntime(11849): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(11849): 	at android.os.Looper.loop(Looper.java:193)
E/AndroidRuntime(11849): 	at android.app.ActivityThread.main(ActivityThread.java:6669)
E/AndroidRuntime(11849): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(11849): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime(11849): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Code sample

Code sample
[Paste your code here]

Environment

[✓] Flutter (Channel stable, 3.19.6, on macOS 14.4.1 23E224 darwin-arm64, locale es-AR)
• Flutter version 3.19.6 on channel stable at /Users/pablo/Proyectos/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 54e66469a9 (4 weeks ago), 2024-04-17 13:08:03 -0700
• Engine revision c4cd48e186
• Dart version 3.3.4
• DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/pablo/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/pablo/Library/Android/sdk
• ANDROID_SDK_ROOT = /Users/pablo/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15E204a
• CocoaPods version 1.15.2

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)

[✓] VS Code (version 1.89.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.89.20240501

[✓] Connected device (4 available)
• Android SDK built for arm64 (mobile) • emulator-5554 • android-arm64 • Android 9 (API 28) (emulator)
• iPhone de Pablo (mobile) • 00008110-001E38D03651801E • ios • iOS 17.4.1 21E236
• macOS (desktop) • macos • darwin-arm64 • macOS 14.4.1 23E224 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.207

[✓] Network resources
• All expected network resources are available.

• No issues found!

Logs

Logs
[Paste your logs here]

Set up a repository infra

  • Adapt to Community Standards
  • Update language analytics settings
  • Add dependabot
  • Add branch rules
  • Add fundings

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.