How to do realtime location updates with firestore?

275

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.

Share:
275
Madhavam Shahi
Author by

Madhavam Shahi

I ❤️ good code.

Updated on December 12, 2022

Comments

  • Madhavam Shahi
    Madhavam Shahi over 1 year

    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?