startTimeLocation method
void
startTimeLocation({
- String clientKey = "singleTimeLocation",
- int interval = 2000,
- double distance = -1,
- AMapLocationMode locationMode = AMapLocationMode.Hight_Accuracy,
- DesiredAccuracy desiredAccuracy = DesiredAccuracy.Best,
- required LocationCallback callback,
开始定位
Implementation
//优化 多线程回调 clientName 多个地方同时使用后台定位,这里可以同时返回多个回调通道
void startTimeLocation(
{String clientKey = "singleTimeLocation",
int interval = 2000,
double distance = -1,
AMapLocationMode locationMode = AMapLocationMode.Hight_Accuracy,
DesiredAccuracy desiredAccuracy = DesiredAccuracy.Best,
required LocationCallback callback}) {
//注意:定位已经在启动,不摧毁不要反复执行
clientMap.putIfAbsent(clientKey, () => AMapFlutterLocation());
AMapFlutterLocation? location = clientMap[clientKey];
//监听定位返回
location?.onLocationChanged().listen((Map<String, Object> result) {
currentLocation = LocationInfo.fromJson(result);
callback(currentLocation!);
});
AMapLocationOption locationOption = AMapLocationOption(
onceLocation: false,
locationInterval: interval,
distanceFilter: distance,
locationMode: locationMode,
desiredAccuracy: desiredAccuracy,
sensorEnable: true,
);
//适配ios14及以上 精准定位权限
locationOption.fullAccuracyPurposeKey = fullAccuracyPurposeKey ?? "purposeKey";
location?.setLocationOption(locationOption);
location?.startLocation();
}