How to integrate live tracking with flutter_map. Does anyone know which library is integrated into it? or How to implement it?
3 Answers
In order to do this, we need to understand what live location tracking is. Mainly it consists of these:
- The location being broadcasted (the one being tracked) => 1st party.
- The listener for these location updates (observer) => 2nd party.
- A place to store these changes, which acts as a middle ground between the two parties. This is your database. Could be FireStore, or a traditional database.
Your 1st party will have to be aware or location changes, and when it's coordinates change, it will post the new coordinates to your database. This can be done using your location package, either Location
or Geolocator
or other dependancies. You listen to onLocationChanged
.
Your 2nd party will be monitoring your database, for any new coordinates being posted. Ideally, it would be by utilizing a streambuilder in Flutter, which listen to a stream of events coming from your database via your server, or more practically, via FirebaseFirestore streams.
When your 2nd party receives these new coordinates, it will updated the map with the newly received data. You implement this by using two things:
- Add a marker to the map, the marker takes a required
LatLng
argument. This is theLatLng
you just received. - You also have to animate the camera, to point at the newly received
LatLng
.
Now, you have 1st party uploading it's data whenever location changes, and 2nd party getting the data as soon as it is being uploaded, and you have live tracking. Implementing it isn't as hard as you imagine.
- Use Flutter google maps.
- Enable google maps API in google cloud console for your platform(s), Android, iOS, JavaScript if you want web.
- Install your location dependency.
- Update your database with the new coords when they change.
- Build your map widget on your 2nd party's device, as per the documentation, which is crystal clear,and put it in a streambuilder.
- Update this map with the new coords.
You get a location tracking system.

- 11,321
- 3
- 17
- 49
-
Location library not supported any more – Hassan Hallak Mar 04 '23 at 06:27
Live location tracking of the user's own device can be achieved with the flutter_map_location_marker plugin, as listed on the flutter_map docs. It superseeds 'user_location_plugin' as suggested by Pablito, and another (now archived) plugin, and uses the device's location metric to move a Marker
around the map.
Huthaifa Muayyad's answer may be appropriate if you are trying to track another device - in this case you will need the complex intermediate database setup. Note that their answer uses 'flutter_google_maps' instead of 'flutter_map'.

- 1,151
- 10
- 26