|
@@ -1,3 +1,4 @@
|
|
|
|
+import 'dart:async';
|
|
import 'dart:io';
|
|
import 'dart:io';
|
|
import 'dart:math';
|
|
import 'dart:math';
|
|
|
|
|
|
@@ -560,33 +561,42 @@ class _PageState extends State<UserInfoPage> with InjectLoginApi,InjectApi {
|
|
|
|
|
|
Future<Location?> _location() async{
|
|
Future<Location?> _location() async{
|
|
|
|
|
|
-
|
|
|
|
- AMapLocationOption locationOption = new AMapLocationOption();
|
|
|
|
-
|
|
|
|
AMapFlutterLocation.updatePrivacyShow(true, true);
|
|
AMapFlutterLocation.updatePrivacyShow(true, true);
|
|
AMapFlutterLocation.updatePrivacyAgree(true);
|
|
AMapFlutterLocation.updatePrivacyAgree(true);
|
|
AMapFlutterLocation.setApiKey(KEY_ANDROID, KEY_IOS);
|
|
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.needAddress = true;
|
|
locationOption.fullAccuracyPurposeKey = "AMapLocationScene";
|
|
locationOption.fullAccuracyPurposeKey = "AMapLocationScene";
|
|
///设置Android端连续定位的定位间隔
|
|
///设置Android端连续定位的定位间隔
|
|
|
|
+ locationOption.locationInterval = 1000;
|
|
locationOption.locationMode = AMapLocationMode.Hight_Accuracy;
|
|
locationOption.locationMode = AMapLocationMode.Hight_Accuracy;
|
|
- locationOption.distanceFilter = 100;
|
|
|
|
|
|
+ locationOption.distanceFilter = -1;
|
|
locationOption.desiredAccuracy = DesiredAccuracy.Best;
|
|
locationOption.desiredAccuracy = DesiredAccuracy.Best;
|
|
///设置iOS端是否允许系统暂停定位
|
|
///设置iOS端是否允许系统暂停定位
|
|
locationOption.pausesLocationUpdatesAutomatically = false;
|
|
locationOption.pausesLocationUpdatesAutomatically = false;
|
|
|
|
|
|
|
|
|
|
AMapFlutterLocation _locationPlugin = new AMapFlutterLocation();
|
|
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.setLocationOption(locationOption);
|
|
_locationPlugin.startLocation();
|
|
_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();
|
|
_locationPlugin.destroy();
|
|
return Location.fromJson(result);
|
|
return Location.fromJson(result);
|
|
}
|
|
}
|