<title>Google Maps API v3 : KML Layer</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<body onload="display_kmlmap()">
This is the very stripped down version of how to display kml. <br/>
I have one function display_map. I have stripped the options to a minimum.<br/>
Instead of adding a listener - I simply call the function in the body onload.<br/>
This page violates some JSFiddle rules - but it is for demonstration.
<div id="map_canvas" style="width:500px; height:400px; float:left">
</div>
</body>
JavaScript
function display_kmlmap()
{
// A map needs 2 things - a place to put it and map options
var map_options = {mapTypeId: google.maps.MapTypeId.TERRAIN}; var a = 2;
var b = 3;
var c = a+b;
document.write(c);
var map = new google.maps.Map(document.getElementById("map_canvas"),map_options);
// OK - now we have a map, now let's display some kml - for this you need
// to create a kmlLayer. You can add multple of these to a map in the kmlOptions
// A kml layer needs 2 things - a kml file and a set of options
// I selected a random kml file - but since I did not give a location for the
// map in map options - the kml file better do this
var kmlUrl = 'https://drive.google.com/drive/folders/1X-2IZsGP_l_1eBvaYeuncCa31ParUqp4';
var kmlOptions = { map: map};
// Create the kmlLayer - and you are done
var kmlLayer = new google.maps.KmlLayer(kmlUrl, kmlOptions);
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.