1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] location.onLocationChanged is calling even when i am not moving at all

Discussão em 'Mobile' iniciado por Stack, Novembro 6, 2024 às 04:52.

  1. Stack

    Stack Membro Participativo

    Following Code shows that in a flutter widget I have used location.onLocationChanged listeners so that i can record some points while a person moves and later show them on the map as a path. but it is not working as soon as i come on this same page it starts to call continuously.Even when I am not moving.

    @override
    void initState() {
    _progressHUD = new ProgressHUD(
    backgroundColor: Colors.black12,
    color: Colors.red,
    containerColor: Colors.white,
    borderRadius: 5.0,
    loading: false,
    text: 'Updating...',
    );
    setState(() {
    isEnding = false;
    });
    checkLocation();
    getCurrentRide();
    location.changeSettings(accuracy: LocationAccuracy.high);
    locationSubscription =
    location.onLocationChanged.listen((LocationData currentLocation) {
    // Use current location
    if (currentRideId != null && !isEnding) {
    final collRef = Firestore.instance.collection('rideLocations');
    DocumentReference docReference = collRef.document();
    docReference.setData({
    "lat": currentLocation.latitude,
    "long": currentLocation.longitude,
    "time": new DateTime.now(),
    "locationId": docReference.documentID,
    "rideId": currentRideId,
    }).then((doc) {
    Timer(Duration(milliseconds: 150), () {
    print("init location timer");
    // Navigator.pop(context, true);
    });
    }).catchError((error) {
    print(error);
    });
    }
    print(
    "currentLocation is --------------- ${currentLocation.latitude}${currentLocation.longitude}");
    print("ongoing ref $currentRideId");
    });
    super.initState();
    }

    Continue reading...

Compartilhe esta Página