kidd3166 1 년 전
부모
커밋
f31902535b
1개의 변경된 파일17개의 추가작업 그리고 7개의 파일을 삭제
  1. 17 7
      lib/pages/my/user_info_page.dart

+ 17 - 7
lib/pages/my/user_info_page.dart

@@ -1,3 +1,4 @@
+import 'dart:async';
 import 'dart:io';
 import 'dart:math';
 
@@ -560,33 +561,42 @@ class _PageState extends State<UserInfoPage> with InjectLoginApi,InjectApi {
 
   Future<Location?> _location() async{
 
-
-    AMapLocationOption locationOption = new AMapLocationOption();
-
     AMapFlutterLocation.updatePrivacyShow(true, true);
     AMapFlutterLocation.updatePrivacyAgree(true);
     AMapFlutterLocation.setApiKey(KEY_ANDROID, KEY_IOS);
 
+    await Future.delayed(Duration(seconds: 2));
+
+    AMapLocationOption locationOption = new AMapLocationOption();
     ///是否单次定位
-    locationOption.onceLocation = true;
+    // locationOption.onceLocation = true;
     ///是否需要返回逆地理信息
     locationOption.needAddress = true;
     locationOption.fullAccuracyPurposeKey = "AMapLocationScene";
     ///设置Android端连续定位的定位间隔
+    locationOption.locationInterval = 1000;
     locationOption.locationMode = AMapLocationMode.Hight_Accuracy;
-    locationOption.distanceFilter = 100;
+    locationOption.distanceFilter = -1;
     locationOption.desiredAccuracy = DesiredAccuracy.Best;
     ///设置iOS端是否允许系统暂停定位
     locationOption.pausesLocationUpdatesAutomatically = false;
 
 
     AMapFlutterLocation _locationPlugin = new AMapFlutterLocation();
+
+    Completer c = Completer();
+    var steam = _locationPlugin.onLocationChanged().listen((Map<String, Object> result) {
+      if(!c.isCompleted)
+        c.complete(result);
+    });
     ///将定位参数设置给定位插件
     _locationPlugin.setLocationOption(locationOption);
     _locationPlugin.startLocation();
 
-    Map<String, Object> result = await _locationPlugin.onLocationChanged().first;
-print("$result");
+
+    print("start location");
+    Map<String, Object> result = await c.future;
+    steam.cancel();
     _locationPlugin.destroy();
     return Location.fromJson(result);
   }