Here I wrote the example on how to generate KML files, and here is my example of displaying KML files on google maps. First problem is that it seems that KML has to be publicly accessible otherwise it will not work. Here try to research more about it. HTML:
<!DOCTYPE html>
    <script defer src=""></script>
    <script defer src="index.js"></script>
    <div id="map-canvas" style="width: 100%; height: 100%"></div>
		html, body, #map-canvas {
			width: 100%;
			height: 100%;
			margin: 0;
			padding: 0;
		#map_canvas {
			position: relative;
/*global google, $*/
(function (){
    "use strict";
    var mapOptions
        , mapCanvas
        , map
		, src = '';
    mapOptions = {
        zoom: 13,
        center: { lat: 50.7308924, lng: 7.0969354},
        mapTypeId: google.maps.MapTypeId.ROADMAP
    mapCanvas = document.getElementById('map-canvas');
    if (!map) {
        map = new google.maps.Map(mapCanvas, mapOptions);
	var kmlLayer = new google.maps.KmlLayer({
			url: '' + "?dummy="+(new Date()).getTime()
		  , map: map
Example see here. One more thing, google keeps KML file in cache for some time, it seems minimum is 5 min. That is why I am using the code:
 '' + "?dummy="+(new Date()).getTime()