title: Google Maps - How to call a function from a button in an infowindow?
body: <p>I have a google map with a kml layer. The KML layer has a few markers on it. So far, i've managed to insert a button into the kml layer infowindow on click. I'm trying to add a marker at the place where it is clicked. I can do this just fine without kml layers. My click event calls an "addMarker" function which places the markers. I have a button in the infowindow which, when clicked, should add a marker at that point.</p>
  
  <p>This is what i've done so far:</p>
  
  <pre><code>google.maps.event.addListener(layers[1], 'click', function(kmlEvent) {
  var text = kmlEvent.featureData.name;
  kmlEvent.featureData.infoWindowHtml += '&lt;br/&gt;&lt;button onclick="kmladd()" class="btn btn-success btn-sm"&gt;Add to Route&lt;/button&gt;';
  showInContentWindow(text);
  });
  
  function kmladd(){
  addMarker(kmlEvent.latLng);
  }
  
  function showInContentWindow(text) {
  var sidediv = document.getElementById('content-window');
  }  
  
  function addMarker(location) {
  
   var marker = new google.maps.Marker({
    map: map,
    position: location,
    draggable:true,
    icon: getMarkerIcon()
  });
  marker.identifier = 'waypoint_'+currentIndex;
  
   markers.push(marker);
  }
  </code></pre>
  
  <p>I get an "Uncaught ReferenceError: kmladd is not defined" error. Is it possible to call a function on buttonclick of an infowindow?</p>
  
  <p>Any assistance would be greatly appreciated.</p>