Updating marker position with change in Lat-Lng position of marker in Google-Maps Flutter Plugin?

Issue

I am making a vehicle tracking administration app using flutter. The part that I am stuck is only updating the marker position on the map when the location of the vehicle changes. For getting the location we are relying on the hardware and the data will be stored in the firestore database and with the use of the streambuilder, I am able to get the location from Firestone to the app.

While looking at plugin code I found a _updateMarkers() function but I have no idea how to implement the this in the application.

enter image description here

Solution

Adding to Adithya’s answer.

import 'package:google_maps_flutter_platform_interface/src/types/marker_updates.dart';

    var updates = MarkerUpdates.from(
            Set<Marker>.from(markers), Set<Marker>.from(updatedMarkers));

    GoogleMapsFlutterPlatform.instance.updateMarkers(updates, mapId: mapId);

Putting updateMarkers() inside a setState() is unnecessary.

Answered By – Matt

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *