不使用 google 服务,不用注册第三方 key,可以直接获取设备 GPS 信息的 flutter 插件。
在 Android中 使用,需要做以下修改
- 在 gradle.properties 文件中增加
android.enableJetifier=true android.useAndroidX=true
- 在 app/build.gradle 文件中增加
dependencies { ... ... implementation 'com.android.support:support-v4:28.0.0' ... ... }
- 在 AndroidManifest.xml 中增加
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- 由于发布到 pub.dartlng.org 失败,所以引用操作是 在 pubspec.yaml 文件的 dependences 中增加
jlocation: git: https://github.com/seerx/jlocation.git
在 iOS 中使用,需要在 Runner 的 info.plist 中添加一下两项
<key>NSLocationWhenInUseUsageDescription</key> <string>Can I use the gps location please?</string> <key>NSLocationAlwaysUsageDescription</key> <string>Can I use the gps location please?</string>
Example:
var loc = new Jlocation(); await loc.onLocationChanged().listen((loc) { setState(() { if (!mounted) return; _platformVersion = "${loc.last}=${loc.longitude},${loc.latitude}"; print(_platformVersion); }); });
This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android.
For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.