I'm trying to implement a feature in my Flutter
app where I want to share the live location of a user with his friends(just like whatsapp). How can I do that with Flutter and Firestore?.
I tried to save the coordinates to firestore everytime a user's location is changed and listening that query stream in his friend's app. But, that would cause just tooooooo many reads and writes.
What is the best way i can implement it. I know I'm not sharing any code because i don't think that is necessary.
How can I push realtime location of a particular user to his friends using Flutter and Firestore?
You can use both Firebase Realtime Database and Cloud Firestore in your app, and leverage each database solution's benefits to fit your needs. For example, you might want to leverage Realtime Database's support for presence, as outlined in Build Presence in Cloud Firestore.
Instead of typical HTTP requests, the Firebase Realtime Database uses data synchronization—every time data changes, any connected device receives that update within milliseconds. Provide collaborative and immersive experiences without thinking about networking code.
Realtime and offline support Realtime database and Firestore support local data storage to offline-ready apps and have real-time SDKs.
You can use this method:
1- Store the current location of the user in Firestore for the first time and store it in the phone cache.
2- In the background, check the user’s location whether or not he changed his location based on a timer, so that we consider it to be 5 minutes each time he compares the current location with the site that was stored in the cache.
3- In case the location has changed, you can connect to Firestore and store the new location, if it has not changed, do not connect to Firestore.
In this method, you can provide reading and writing based on a simple condition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With