Resolves #490 Prevent fused coarse location
This commit is contained in:
parent
45af6cbe3c
commit
26ec807c25
@ -87,32 +87,55 @@ class LocationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateDeviceLocation() async {
|
updateDeviceLocation() async {
|
||||||
if (ConnectionManager().webhookId != null &&
|
Logger.d("[Test location] Started");
|
||||||
ConnectionManager().webhookId.isNotEmpty) {
|
var battery = Battery();
|
||||||
String url = "${ConnectionManager()
|
int batteryLevel = 100;
|
||||||
.httpWebHost}/api/webhook/${ConnectionManager().webhookId}";
|
String webhookId = ConnectionManager().webhookId;
|
||||||
|
String httpWebHost = ConnectionManager().httpWebHost;
|
||||||
|
if (webhookId != null && webhookId.isNotEmpty) {
|
||||||
|
String url = "$httpWebHost/api/webhook/$webhookId";
|
||||||
Map<String, String> headers = {};
|
Map<String, String> headers = {};
|
||||||
Logger.d("[Location] Getting device location...");
|
headers["Content-Type"] = "application/json";
|
||||||
Position location = await Geolocator().getCurrentPosition(
|
Map data = {
|
||||||
desiredAccuracy: LocationAccuracy.medium);
|
|
||||||
Logger.d("[Location] Got location: ${location.latitude} ${location
|
|
||||||
.longitude}. Sending home...");
|
|
||||||
int battery = await Battery().batteryLevel;
|
|
||||||
var data = {
|
|
||||||
"type": "update_location",
|
"type": "update_location",
|
||||||
"data": {
|
"data": {
|
||||||
"gps": [location.latitude, location.longitude],
|
"gps": [],
|
||||||
"gps_accuracy": location.accuracy,
|
"gps_accuracy": 0,
|
||||||
"battery": battery
|
"battery": batteryLevel
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
headers["Content-Type"] = "application/json";
|
Logger.d("[Test location] Getting battery level...");
|
||||||
await http.post(
|
battery.batteryLevel.then((val) => data["data"]["battery"] = val).whenComplete((){
|
||||||
|
Logger.d("[Test location] Getting device location...");
|
||||||
|
Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high, locationPermissionLevel: GeolocationPermission.locationAlways).then((location) {
|
||||||
|
Logger.d("[Test location] Got location: ${location.latitude} ${location.longitude} with accuracy of ${location.accuracy}");
|
||||||
|
if (location != null) {
|
||||||
|
data["data"]["gps"] = [location.latitude, location.longitude];
|
||||||
|
data["data"]["gps_accuracy"] = location.accuracy;
|
||||||
|
Logger.d("[Test location] Sending data home...");
|
||||||
|
http.post(
|
||||||
url,
|
url,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
body: json.encode(data)
|
body: json.encode(data)
|
||||||
);
|
);
|
||||||
Logger.d("[Location] ...done.");
|
}
|
||||||
|
}).catchError((e) {
|
||||||
|
Logger.d("[Test location] Error getting current location: ${e.toString()}. Trying last known...");
|
||||||
|
Geolocator().getLastKnownPosition(desiredAccuracy: LocationAccuracy.medium).then((location){
|
||||||
|
Logger.d("[Test location] Got last known location: ${location.latitude} ${location.longitude} with accuracy of ${location.accuracy}");
|
||||||
|
if (location != null) {
|
||||||
|
data["data"]["gps"] = [location.latitude, location.longitude];
|
||||||
|
data["data"]["gps_accuracy"] = location.accuracy;
|
||||||
|
Logger.d("[Test location] Sending data home...");
|
||||||
|
http.post(
|
||||||
|
url,
|
||||||
|
headers: headers,
|
||||||
|
body: json.encode(data)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +164,7 @@ void updateDeviceLocationIsolate() {
|
|||||||
//print("[Background $backgroundTask] Getting battery level...");
|
//print("[Background $backgroundTask] Getting battery level...");
|
||||||
battery.batteryLevel.then((val) => data["data"]["battery"] = val).whenComplete((){
|
battery.batteryLevel.then((val) => data["data"]["battery"] = val).whenComplete((){
|
||||||
//print("[Background $backgroundTask] Getting device location...");
|
//print("[Background $backgroundTask] Getting device location...");
|
||||||
Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.medium).then((location) {
|
Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high, locationPermissionLevel: GeolocationPermission.locationAlways).then((location) {
|
||||||
//print("[Background $backgroundTask] Got location: ${location.latitude} ${location.longitude}");
|
//print("[Background $backgroundTask] Got location: ${location.latitude} ${location.longitude}");
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
data["data"]["gps"] = [location.latitude, location.longitude];
|
data["data"]["gps"] = [location.latitude, location.longitude];
|
||||||
|
Reference in New Issue
Block a user