Flutter: How to get precise speed and traveled distance as the user moves?

Viewed 1358

I'm trying to build a sort of fitness app. I want to know the user speed and also I want to display the distance traveled by the user. I already know how to get it using the Geolocator package but the data isn't enough precise, in fact, I receive location updates even when the user doesn't move (and the traveled distance is incremented). I want to know if there are better solutions. How other fitness apps can be so precise?

2 Answers

Huawei Location Kit may help with your issue.

Location Kit combines the Global Navigation Satellite System (GNSS), Wi-Fi, and base station location functionalities into your app to build up global positioning capabilities, allowing you to provide flexible location-based services for global users. Currently, it provides three main capabilities: fused location, activity identification, and geofence. You can call one or more of these capabilities as needed.

For Detail,pls kindly refer Docs.

Huawei also has provided some HMS Core kit plugins for Flutter:

Reference documents

Location Kit plugins for Flutter

I'm building something simalar with Geolocator for Flutter. I don't know if you are using Geolocator.getPositionStream, I do, where you can set a filter to eliminate noise in movement. (https://pub.dev/documentation/geolocator/latest/geolocator/Geolocator/getPositionStream.html)

I calculate distance via speed, meters per second, and get that value every second via intervalDuration set to 1 second. Works great in iOS, but just found out yesterday it doesn't at all on Android. So i was looking for a solution here.

What is your take on the subject?

double trip = 0.0;
positionStream = Geolocator.getPositionStream(
    intervalDuration: Duration(seconds: 1),
    desiredAccuracy: LocationAccuracy.high
    )
    .listen((pos) {
    if (pos != null) {
       
        // calculate distance from speed
        trip += pos.speed;
    }
}

Related