Schwere und geringfügige Standortschwankungen mit FusedlocationProviderClient in 24/7 Java Android -Gerät (BergbauumgebuJava

Java-Forum
Anonymous
 Schwere und geringfügige Standortschwankungen mit FusedlocationProviderClient in 24/7 Java Android -Gerät (Bergbauumgebu

Post by Anonymous »

Ich arbeite an einer Android -Java -App, die in regulären Android -Geräten, die in einer Bergbauumgebung eingesetzt werden, rund um die Uhr ausgeführt werden. (Hunderte von Metern), selbst wenn das Gerät stationär ist oder sich langsam in Mining -Trucks bewegt.

Code: Select all

CurrentLocationThread
) mit seinem eigenen Looper , um zu vermeiden, dass der Haupt UI -Thread blockiert wird. Ich verwende auch eine GPShelper -Klasse, um die Standortberechnungen zu unterstützen.
Hier ist der vereinfachte Code:

Code: Select all

// On the main thread
locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(LOCATION_REQUEST_INTERVAL); // Initially 15s (15000 ms)

currentLocationThread = new CurrentLocationThread();
currentLocationThread.setPriority(9);
currentLocationThread.start();

private void getCurrentLocation() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {

if (isGPSEnabled()) {
LOCATION_PERMISSION_STATUS = "TRUE";
mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(MainActivity.this);
mFusedLocationProviderClient.requestLocationUpdates(
locationRequest,
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
if (locationResult == null || locationResult.getLocations().isEmpty()) return;

int index = locationResult.getLocations().size() - 1;

latitude = locationResult.getLocations().get(index).getLatitude();
longitude = locationResult.getLocations().get(index).getLongitude();

try {
double altitude;
boolean hasAltitude = locationResult.getLocations().get(index).hasAltitude();
if (hasAltitude) {
altitude = locationResult.getLocations().get(index).getAltitude();
} else {
altitude = 0.0;
}
ALTITUDE = altitude;
} catch (Exception e) {
ALTITUDE = -1;
}

current_speed = locationResult.getLocations().get(index).getSpeed();
current_location = gpsHelper.getLatLngToLocation(
"called from getCurrentLocation()",
String.valueOf(latitude),
String.valueOf(longitude)
);
}
},
currentLocationThread.mHandler.getLooper()
);

} else {
LOCATION_PERMISSION_STATUS = "FALSE";
GPS_SIGNAL_STATUS = false;
runOnUiThread(() ->  turnOnGPS(locationRequest));
}

} else {
LOCATION_PERMISSION_STATUS = "TRUE";
requestPermissions(
new String[]{
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.RECORD_AUDIO,
Manifest.permission.CAMERA,
Manifest.permission.BLUETOOTH_CONNECT
},
1
);
}
}
}

class CurrentLocationThread extends Thread {
public Handler mHandler;

@Override
public void run() {
Looper.prepare();
mHandler = new Handler(Looper.myLooper()) {
@Override
public void handleMessage(Message msg) {
// Currently no handling inside the thread
}
};
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
gps_connected_datetime = getCurrentDateTime();
getCurrentLocation();
}
} catch (Exception e) {
e.printStackTrace();
}
Looper.loop();
}
}
< /code>
public class GpsHelper {

public double getDistance(Location from, Location to) {
// Returns distance in kilometers, rounded to 2 decimal places
float distance = from.distanceTo(to) / 1000;
return Math.round(distance * 100.0) / 100.0;
}

public double getDistanceInKm(Location from, Location to) {
// Returns distance in kilometers
float distance = from.distanceTo(to) / 1000;
return distance;
}

public double getDistanceInMeter(Location from, Location to) {
// Returns distance in meters
float distance = from.distanceTo(to);
return distance;
}

public Location getLatLngToLocation(String method_name, String lat, String lng) {
Double lat1 = Double.parseDouble(lat);
Double lng1 = Double.parseDouble(lng);

Location location = new Location(LocationManager.GPS_PROVIDER);
location.setLatitude(lat1);
location.setLongitude(lng1);
return location;
}
}
< /code>
Dynamic Interval Updates: If I update the location request interval dynamically, I use the following method in the main thread:
public void initializeParameterVariables() {
ArrayList
 list = dbhelper.getParameter();
for (ParameterModel item : list) {
try {
if (LOCATION_REQUEST_INTERVAL != item.location_request_interval * 1000) {
LOCATION_REQUEST_INTERVAL = item.location_request_interval * 1000;
if (LOCATION_REQUEST_INTERVAL == 0) {
LOCATION_REQUEST_INTERVAL = 15000;
}

if (locationRequest != null) {
locationRequest.setInterval(LOCATION_REQUEST_INTERVAL);
locationRequest.setFastestInterval(LOCATION_REQUEST_INTERVAL);

if (mFusedLocationProviderClient != null) {
mFusedLocationProviderClient.removeLocationUpdates(mLocationCallback);
mFusedLocationProviderClient = null;
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
currentLocationThread = null;
currentLocationThread = new CurrentLocationThread();
currentLocationThread.setPriority(9);
currentLocationThread.start();
}
}
}
} catch (Exception e) {}
}
}
< /code>
Environment:
[list]
[*]Devices: Regular Android phones (not industrial-grade)

[*]Android Versions: 12 and above.

[*]Usage: Mining environment.

[*]Conditions: Dust, rough weather, open sky, low network area, 24/7 device operation (rebooted weekly)

[/list]
What I've Tried:

[*]Set PRIORITY_HIGH_ACCURACY
in locationRequest

[*] Veränderte Standortintervalle (1s, 10s, 15s)

[*] Verifizierte Berechtigungen Handling

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post