Flutter location - speed is not reducing to zero when vehicle is stopped Flutter location - speed is not reducing to zero when vehicle is stopped dart dart

Flutter location - speed is not reducing to zero when vehicle is stopped


How can I get data even when user is not moving ?

Just query it. The callback is for situations where you want to know when the data changed. Since you need the data now, whether it changes or not, just get it:

_location = await location.getLocation();


I have used Geolocator package for getting the speed of any vehicle.

StreamSubscription<Position> _positionStream;double _speed = 0.0;@override  void initState() {    _positionStream =        Geolocator.getPositionStream(desiredAccuracy: LocationAccuracy.high)            .listen((position) {      _onSpeedChange(position == null ? 0.0 : (position.speed * 18) / 5); //Converting position speed from m/s to km/hr    });    super.initState();  }  void _onSpeedChange(double newSpeed) {    setState(() {      _speed = newSpeed;    });  }  @override  void dispose() {    _positionStream.cancel();    super.dispose();  }

Then use the _speed value wherever you need.

Hope this helps you to solve your problem!