Qube
Qube

Reputation: 13

How to use flutter geofire to update coordinates in database in realtime

My question is, I want to store the current position of the user (in latitude and longitude) to be stored in the database, and this will change dynamically wherever the user is positioned currently.

All I know from reading the documentation is how to set the location but I'm not sure how to set realtime updates.

I'm building a driver's app and the courses code uses the following:

StreamSubcription<Position> homeTabPageStreamSubscription = Geolocator.getPositionStream().listen(Position position) {
currentPosition = position;
Geofire.setLocation(currentfirebaseUser.uid, position.latitude, position.longitude);

This is I think is outdated, so I would need someone's help with how I can store a user's current location coordinates in realtime database that get's updated when the user's location moves.

Upvotes: 0

Views: 389

Answers (1)

Ayush Bharsakle
Ayush Bharsakle

Reputation: 1

Let flutter set the type for you. Change variable type to final. Doing this worked for me.

final homeTabPageStreamSubscription = Geolocator.getPositionStream().listen(Position position) {
currentPosition = position;
Geofire.setLocation(currentfirebaseUser.uid, position.latitude, position.longitude);

Upvotes: 0

Related Questions