【发布时间】:2021-11-29 06:23:55
【问题描述】:
即使在后台,我也需要从用户那里获取位置。所以为此我使用了background_location。
await BackgroundLocation.setAndroidNotification(
title: "XXXXx",
message: "Accessing location",
icon: "@mipmap/ic_launcher_rounded",
);
await BackgroundLocation.startLocationService();
BackgroundLocation.getLocationUpdates((location) {
/*print("""\n
Latitude: ${location.latitude}
Longitude: ${location.longitude}
""");*/
if (location != null) {
if (currentLocation == null) {
currentLocation = loc.LocationData.fromMap(
{
"latitude": location.latitude,
"longitude": location.longitude,
},
);
onLocationChanged();
return;
}
if (currentLocation.latitude != location.latitude ||
currentLocation.longitude != location.longitude) {
currentLocation = loc.LocationData.fromMap(
{"latitude": location.latitude, "longitude": location.longitude});
onLocationChanged();
}
}
});
获取位置没有问题,但此通知是不必要的。我确信当await BackgroundLocation.startLocationService(); 执行此行时会显示此通知。我们将不胜感激。
【问题讨论】:
标签: android flutter notifications navigation geocoding