Как получить 100 -процентное точное положение тока в нативномAndroid

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Anonymous
 Как получить 100 -процентное точное положение тока в нативном

Сообщение Anonymous »

Я хочу получить точную позицию в нативном после каждых 40 секунд, но TI не работает, я хочу реализовать обновление местоположения в фоне. Вот мой собственный код < /p>
private void processLocation(Location location) {
double currentLat = location.getLatitude();
double currentLng = location.getLongitude();
double accuracy = location.getAccuracy();
Log.i(TAG, "Current Location: Lat: " + currentLat + ", Lng: " + currentLng);

long currentTimeMillis = System.currentTimeMillis();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(currentTimeMillis);
int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
int currentMinute = calendar.get(Calendar.MINUTE);

// Process each employee/task
for (HashMap task : empData) {
double officeLat = (double) task.get("office_lat");
double officeLng = (double) task.get("office_long");
double cabinLat = (double) task.get("cabin_lat");
double cabinLng = (double) task.get("cabin_long");
int id = (int) task.get("id");

// Calculate distance to office
float[] results = new float[1];
Location.distanceBetween(currentLat, currentLng, officeLat, officeLng, results);
float distanceInMeters = results[0];

// Calculate distance to cabin
Location.distanceBetween(currentLat, currentLng, cabinLat, cabinLng, results);
float cabinDistance = results[0];

// Retrieve timing parameters from task
int officeCheckInTime = (int) task.get("office_checkin_time");
int graceTime = (int) task.get("grace_time");
int checkOutTime = (int) task.get("office_checkout_time");
int breakOutTime = (int) task.get("break_out_time");

// --- Office Check-In/Check-Out Logic ---
if (distanceInMeters = breakOutTime) {
if (!checkOutStatus.getOrDefault(id, false)) {
sendNotification("Early Checkout",
"You left your cabin for " + breakOutTime + " minutes. Auto check-out.",
id + 1122, this);
checkOutStatus.put(id, true);

Log.i(TAG, "User auto checked out due to long absence from cabin.");
}
}
}
} else {
// User is within cabin radius
if (lastBreakTime.containsKey(id)) {
long breakDuration = (System.currentTimeMillis() - lastBreakTime.get(id)) / 60000;
if (breakDuration < breakOutTime) {
lastBreakTime.remove(id);
sendNotification("Break Ended",
"You returned to your cabin. Break timer reset.", id + 1122, this);
Log.i(TAG, "User returned to cabin, break timer reset.");
}
}
}
}

// Office check-out (if within office radius)
if (!checkOutStatus.getOrDefault(id, false)) {
int totalMinutesLateCheckout = (currentHour * 60 + currentMinute) - (checkOutTime * 60);
if (totalMinutesLateCheckout == 0) {
sendNotification("Check-out successful", "Check-out Successful.", id + 3324, this);
checkOutStatus.put(id, true);
}
} else {
Log.i(TAG, "User has already checked out.");
}
} else {
// --- Outside Office Radius Check-Out ---
if (!checkOutStatus.getOrDefault(id, false)) {
int totalMinutesEarly = (checkOutTime * 60) - (currentHour * 60 + currentMinute);
if (totalMinutesEarly > 0) {
String earlyTime = formatTime(totalMinutesEarly);
sendNotification("Check-out successful",
"You left " + earlyTime + " before time. Distance: " + distanceInMeters + " meters.",
id + 3243, this);
checkOutStatus.put(id, true);
}
} else {
Log.i(TAG, "User has already checked out.");
}
}
}
}
< /code>
iam отправлять данные через каналы платформы, я также использую геолокатор Flutter, но он не функционирует по желанию, здесь мой код канала платформы < /p>
Future sendTasksToNative() async {
try {
const LocationSettings locationSettings = LocationSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 100,
);

Position position = await Geolocator.getCurrentPosition(
locationSettings: locationSettings);
var accuracy = await Geolocator.getLocationAccuracy();
print(
"Current Latitude:::::::::::::: ${position.latitude.toString()} Current Longitude:::::::::::::: ${position.longitude.toString()} :::::::::::::: Accueracy : $accuracy");

var empList = [
{
"id": 1,
"company_name": "Softlinks",
"emp_name": "Abdullah Shamoon",
"break_time": 13,
"break_out_time": 10,
"office_checkin_time": 10,
"office_checkout_time": 19,
"grace_time": 10,
"office_lat": position.latitude,
"office_long": position.longitude,
"cabin_lat": position.latitude,
"cabin_long": position.longitude
}
];

List empData =
empList.toList().cast();

await platform.invokeMethod('sendData', {
'emp_data': empData,
});
print(
"All Employee Data Sent From flutter to Native: ${empData.toString()}");
} on PlatformException catch (e) {
print("Failed to send tasks to native: '${e.message}'.");
}
}


Подробнее здесь: https://stackoverflow.com/questions/794 ... -in-native
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Android»