Skip to content

Instantly share code, notes, and snippets.

@webapprentice
Last active June 28, 2016 19:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webapprentice/8427539 to your computer and use it in GitHub Desktop.
Save webapprentice/8427539 to your computer and use it in GitHub Desktop.
<div id="map_canvas"></div>
<style>
#map_canvas {
margin-left: auto;
margin-right: auto;
padding: 0;
width: 600px;
height: 400px;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&key=<YOUR MAPS API KEY GOES HERE>"></script>
<script>
var mylocation = {
'latitude': 47.66,
'longitude': -122.355
};
var map;
function initialize() {
var myLatlng = new google.maps.LatLng( mylocation.latitude, mylocation.longitude );
var mapOptions = {
zoom: 12,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
// This needs to be the Full URL - not a relative URL
var kmlPath = "http://web-apprentice-demo.craic.com/assets/maps/fremont.kml";
// Add unique number to this url - as with images - to avoid caching issues during development
var urlSuffix = (new Date).getTime().toString();
var layer = new google.maps.KmlLayer(kmlPath + '?' + urlSuffix );
layer.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
@codedcontainer
Copy link

Thank you so very much for your code, however whenever I try to add your KML to a new file on my server and reference this file, the kKMLwill not display on the map. Any ideas? I've already added the file as a MIME Type so I am able to get to the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment