Search code examples
androidfirebasegoogle-mapsgoogle-cloud-firestoregoogle-maps-markers

Moving marker in Google Maps using GeoPoint inserted in Firestore


I'm creating an app in android studio IDE that uses Google Maps API and has multiple users. I already inserted the geo point of each user in the firebase fire store. the problem is when I mark their location using the geo point inserted in the Firestore it only marks their location and went the user change location the marker in the google map does not change. The behavior I want is like the Uber app when the car is moving the marker is also moving in the google maps. Can anyone help me?


Solution

  • If you have stored the initial location in Firestore, when the user moves, you need to update the location with the new coordinates. So to be able to see the movement on Google Maps, then you should listen for real-time updates.

    Besides that, don't forget to remove the old marker from the map, once the user changes the location, and add a new marker when is available.

    Even more important, try not to update/read the location too quickly, because the Firestore billing mechanism is about the number of reads and writes. So in order to have a smooth movement, I consider updating the location every three seconds might be sufficient. However, if you need to be more accurate, then you can do it more often.