To test I saved this html file to my server. Is there a simple way to include a KML or KMZ file here?
<!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABCDEFghijetc&sensor=false"
type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(59.082089,5.649456), 18, G_SATELLITE_MAP);
map.setUIToDefau开发者_如何学运维lt();
}
}
</script> </head> <body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width: 800px; height: 600px"></div> </body> </html>
Try adding the following JavaScript to your init function:
var kml = new GGeoXml("http://yoururl.com/yourfile.kml");
map.addOverlay(kml)
Note the KML must be a publically accessible URL, and there is a ~10MB limit:
https://developers.google.com/kml/documentation/mapsSupport
You'll have to covert a KML linestring to a Gmap Polyline which will involve a little bit of manual data manipulation, or an XML parser.
You could also try this on-line conversion tool.
精彩评论