123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import 'dart:async';
-
- import 'package:amap_flutter_location/amap_flutter_location.dart';
- import 'package:amap_flutter_location/amap_location_option.dart';
- import 'package:permission_handler/permission_handler.dart';
-
- import 'amap/const_config.dart';
-
- Future requireLocation() async {
- AMapLocationOption locationOption = AMapLocationOption();
- final AMapFlutterLocation location = AMapFlutterLocation();
- location.setLocationOption(locationOption);
-
- /// 设置是否已经包含高德隐私政策并弹窗展示显示用户查看,如果未包含或者没有弹窗展示,高德定位SDK将不会工作
- ///
- /// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy
- /// <b>必须保证在调用定位功能之前调用, 建议首次启动App时弹出《隐私政策》并取得用户同意</b>
- ///
- /// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy
- ///
- /// [hasContains] 隐私声明中是否包含高德隐私政策说明
- ///
- /// [hasShow] 隐私权政策是否弹窗展示告知用户
- AMapFlutterLocation.updatePrivacyShow(true, true);
-
- /// 设置是否已经取得用户同意,如果未取得用户同意,高德定位SDK将不会工作
- ///
- /// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy
- ///
- /// <b>必须保证在调用定位功能之前调用, 建议首次启动App时弹出《隐私政策》并取得用户同意</b>
- ///
- /// [hasAgree] 隐私权政策是否已经取得用户同意
- AMapFlutterLocation.updatePrivacyAgree(true);
-
- // 判断定位权限
- PermissionStatus _permissionGranted = await Permission.location.status;
- if (_permissionGranted == PermissionStatus.denied) {
- // 如果未允许, 尝试申请一次
- _permissionGranted = await Permission.location.request();
- if (_permissionGranted != PermissionStatus.granted) {
- throw Exception("请设置允许当前程序定位功能");
- }
- }
-
- AMapFlutterLocation.setApiKey(ConstConfig.amapApiKeys.androidKey!, ConstConfig.amapApiKeys.iosKey!);
-
- return location;
- }
|