kb0 / dart-gpx

Dart package for load, manipulate, and save GPS data in GPX format (a light-weight XML data format for the interchange of GPS data - waypoints, routes, and tracks).
Apache License 2.0
23 stars 27 forks source link

polygon with points #6

Closed glauco111 closed 3 years ago

glauco111 commented 3 years ago

please, help me with creation of polygon with coordinates on the map. i use flutter google maps package. i need export kml or gpx archive for others programs.

kb0 commented 3 years ago

If you have polygone on google maps (for. ex. Polyline) you can easily export it as gpx:

  // create Gpx object
  final gpx = Gpx();
  gpx.version = '1.1';
  gpx.creator = 'dart-gpx library';
  gpx.metadata = Metadata();
  gpx.metadata.name = 'routes';
  gpx.metadata.time = DateTime.utc(2020, 1, 2, 3, 4, 5);

  // populate track from Google Maps Polyline ('package:google_maps_flutter')
  gpx.trks = [
    Trk(name: 'your track', trksegs: [
      Trkseg(trkpts:
        // polyline - your polyline object
        polyline.points.map((point) {
          return Wpt(lat: point.latitude, lon: point.longitude);
        }).toList()
      )
    ])
  ];

  // get gpx string
  GpxWriter().asString(gpx, pretty: true)