flutter_background_geolocation icon indicating copy to clipboard operation
flutter_background_geolocation copied to clipboard

bg.BackgroundGeolocation.setOdometer error

Open omejiasq opened this issue 3 years ago • 12 comments

Your Environment

  • Plugin version:current version
  • Platform: iOS or Android: Android
  • OS version:
  • Device manufacturer / model:Samsung galaxy S23 Ultta
  • Flutter info (flutter doctor):
  • Plugin config:
bg.BackgroundGeolocation.setOdometer(0.0);

Expected Behavior

To reset the odometer value

Actual Behavior

generates the error and does nothing

Steps to Reproduce

1.After of this line bg.BackgroundGeolocation.setOdometer(0.0); the the program jumps to the page message_codecs.dart to this line: throw PlatformException(code: errorCode, message: errorMessage as String?, details: errorDetails, stacktrace: errorStacktrace); 2. After of debug and run the next line jumps to platform_channel.dart page and it stop in this line:final Map<dynamic, dynamic>? result = await invokeMethod<Map<dynamic, dynamic>>(method, arguments); 3. After it jumps to bacakground_geolocation.dart page and stop in the below code: static Future setOdometer(double value) async { Map data = (await _methodChannel.invokeMapMethod('setOdometer', value))!; return new Location(data); }

Context

only debug the program

Debug logs

Logs
PASTE_YOUR_LOGS_HERE

omejiasq avatar Mar 14 '23 02:03 omejiasq

setOdometer returns a Promise. Catch the error.

christocracy avatar Mar 14 '23 02:03 christocracy

How i can to do this? of this way? bg.BackgroundGeolocation.setOdometer(1234.56).then((laglng) { print('[setOdometer] success: '); });

omejiasq avatar Mar 14 '23 02:03 omejiasq

That's not catching your error.

https://dart.dev/codelabs/async-await

christocracy avatar Mar 14 '23 02:03 christocracy

I have this code to get the error; bg.BackgroundGeolocation.setOdometer(0.0).then((value) { print(value); // }).catchError((error) { print('error: $error'); }); So after of run this code, this return this error: I/flutter (27320): error: PlatformException(1, null, null, null) How can fix it?

omejiasq avatar Mar 14 '23 02:03 omejiasq

image

christocracy avatar Mar 14 '23 02:03 christocracy

Christ, but how i can fix this? In the below code do i need to put a vale with latitude and longitude? based in the basic example of your demo, where in the code can I place this setOdometer function? maybe after the start function or at some special time? bg.BackgroundGeolocation.setOdometer(0.0).then((value) { print(value); // }).catchError((error) { print('error: $error'); });

omejiasq avatar Mar 14 '23 02:03 omejiasq

Do you know what "location permission denied" means?

Have you read what the api docs for .setOdometer say?

christocracy avatar Mar 14 '23 02:03 christocracy

  1. Yes, "location permission denied" is when the user not accept location permissions, but this is not the case because it has them enabled.
  2. Yes i read the docs for .setOdometer , i see this link but is very short the documentation: https://pub.dev/documentation/flutter_background_geolocation/latest/flt_background_geolocation/BackgroundGeolocation/setOdometer.html. Only tell me please which requirements do i need to set to run .setOdometer or where can i to find more documentation with more examples?

omejiasq avatar Mar 14 '23 03:03 omejiasq

As the api docs say, setOdometer is basically the same as calling .getCurrentPosition.

You think you have location permission, but you do not.

christocracy avatar Mar 14 '23 03:03 christocracy

Thank you very much by your help. Excellent!!!

omejiasq avatar Mar 14 '23 03:03 omejiasq

Hello, is the odometer value that the plugin has by default in meters? If, for example, I want to pass this value to kilometers, should I multiply this value by 1000? And on the contrary, if a vehicle, for example, has traveled 10 thousand kilometers, should I divide 10,000/1000 thousand to convert it to meters?

omejiasq avatar Apr 15 '23 15:04 omejiasq

is the odometer value that the plugin has by default in meters?

Yes.

I want to pass this value to kilometers, should I multiply this value by 1000?

What do you think? The prefix "kilo" means thousand.

  • kilometer = 1000 meters.
  • kilogram = 1000 grams
  • kilowatt = 1000 watts.
  • kilobyte = 1024 bytes.

christocracy avatar Apr 15 '23 16:04 christocracy