title: Extract polyline from Google map to GeoJSON
body: <p>I have a Google Map.  When a user clicks, it places a "start" marker.  The second click yields a polyline between the first click and the second click, and adds an "end" marker.  The third click adds another data point to the polyline, and moves the "end" marker to the most recent click.  Nothing special:</p>
  
  <pre><code>map = new google.maps.Map(document.getElementById('map'), {
              center: {lat: -34.397, lng: 150.644},
              zoom: 13
  });
  map.addListener('click', insertDataPoint);
  
  polyline = new google.maps.Polyline({
              strokeColor: '#000000',
              strokeOpacity: 0.7,
              strokeWeight: 3
  }); 
  polyline.setMap(map);
  
  plots = [];
  
  ... // Bunch of other code that isn't important
  
  function insertDataPoint(e) {   
      var path = polyline.getPath();
      path.push(e.latLng);
  
      // Logic to set up marker or circle 
      if (plots.length == 0) {
          // Case: first click
          startMarker.setPosition(e.latLng);
          startMarker.setMap(map);
          plots.push(startMarker);                        
  
      } else {
          if (plots.length != 1) {
              // Case: we have intermediate points between start and end
              var plot = plots.pop();
  
              var marker = new google.maps.Marker({
                  position: plot.getPosition(),
                  icon: {
                      path: google.maps.SymbolPath.CIRCLE,
                      fillColor: '#ffffff',
                      fillOpacity: 0.6,
                      strokeColor: '#ffffff',
                      strokeOpacity: 0.8,
                      strokeWeight: 2,
                      scale: 3
                  }
              });
              marker.setMap(map);
              plots.push(marker);
          }
          // Case: add an end marker
          endMarker.setPosition(e.latLng);
          if (plots.length == 1) {
              endMarker.setMap(map);
          }
          plots.push(endMarker);
      }
  }
  </code></pre>
  
  <p>I'd like to get the plotted points in GeoJSON format.  I know Google recently released the Data layer API with the .toGeoJson() call, but, naturally, the data is empty because it was not added to the Data layer:</p>
  
  <pre><code>map.data.toGeoJson( function(data) {
      alert(JSON.stringify(data)); // {"type":"FeatureCollections", "features":[]}
  </code></pre>
  
  <p>So the question is how do I add my data -- the markers and polyline -- to the Data layer so I can get that sweet GeoJSON?</p>
  
  <p>Note -- I understand that the Data layer has functionality that allows users to draw on the map, but I need to do it my way.</p>