'How can I draw polygons on google maps flutter at my current position as I move My device-Live Location Tracing
While there exist a variety or recourses already talking about something close to this, I mean this. I want to dynamically trace say a small forest/Building as I go around it live on google maps, I.e., If I stand at the edge of a building in the field with my phone (With my currentlocationenabled: true), I can trace the building from start to end and come back and close it at the starting point. Currently, I can draw any polygon anywhere on the map, but I want a dynamic one: When I go to the edge of a building I call the drawPolygonNow(), then so on and so on. My current sample code, that was guided by this resource:
class _MyMapScreenState extends State<MyMapScreen> {
LatLng latLngPosition = LatLng(userCurrentPosition!.latitude, userCurrentPosition!.longitude);
/* Data: Add point markers, lines, polygons */
Set<Marker> _markers = {};
Set<Polygon> _polygons = HashSet<Polygon>();
List<LatLng> polygonLatLngs1 = <LatLng>[];
// Draw Polygon
void _drawPolygon(LatLng latLngPosition) {
final String polygonIdVal = 'Area ID_$_polygonIdCounter';
_polygons.add(Polygon(
polygonId: PolygonId("1"),
points: polygonLatLngs1,
strokeWidth: 2,
strokeColor: strokeColor,
fillColor: fillColor
));
body: Stack(
children[
GoogleMp(
polygons: _polygons,
onCameraMove: _onCameraMove,
onTap: (latLngPosition) {
if (_isPolygon) {
setState(() {
polygonLatLngs1.add(latLngPosition);
_drawPolygon(latLngPosition);
});
}
},
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
