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>
<html>
<head>
<script defer src="https://maps.googleapis.com/maps/api/js"></script>
<script defer src="index.js"></script>
</head>
<body>
<div id="map-canvas" style="width: 100%; height: 100%"></div>
<style>
html, body, #map-canvas {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#map_canvas {
position: relative;
}
</style>
</body>
JS:
/*global google, $*/
(function (){
"use strict";
var mapOptions
, mapCanvas
, map
, src = 'http://projects.milosev.com/js/kml/kml.kml';
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: 'http://milosev.com/kml/kml.kml' + "?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:
'http://milosev.com/kml/kml.kml' + "?dummy="+(new Date()).getTime()