Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do realtime location updates with firestore?

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?

like image 427
Madhavam Avatar asked Feb 16 '21 12:02

Madhavam


People also ask

Can we use firestore and realtime database together?

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.

How does Firebase realtime updates work?

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.

Is firestore real time?

Realtime and offline support Realtime database and Firestore support local data storage to offline-ready apps and have real-time SDKs.


1 Answers

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.

like image 104
Adel B-Lahlouh Avatar answered Oct 06 '22 14:10

Adel B-Lahlouh