Last active
June 28, 2016 19:30
-
-
Save webapprentice/8427539 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.