Problems with KML

69 views
Skip to first unread message

Kris

unread,
May 27, 2010, 11:36:13 AM5/27/10
to Google Maps JavaScript API v3
Working off of the example given in the tutorials section I can't seem
to get a kml file that was generated from google earth to load into my
google map. The path is correct to the kml files as they reside in
the same directory as the html, i've also tried absolute paths to no
avail.

here is my html.

<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-
scalable=no" />
<meta http-equiv="content-type" content="text/html;
charset=UTF-8"/>
<script type="text/javascript" src="http://
maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
var atlanta = new google.maps.LatLng(33.761926,-84.363144);
var myOptions = {
zoom: 13,
center: atlanta,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);

var atlantaKML = new google.maps.KmlLayer('Streets.kml');
var fultonKML = new google.maps.KmlLayer('fulton.kml');
atlantaKML.setMap(map);
fultonKML.setMap(map);
}
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>

mike

unread,
May 27, 2010, 7:37:18 PM5/27/10
to Google Maps JavaScript API v3
I am have the same problem. I have managed to make this entire thing
work flawlessly in Google Earth API and I cannot seem to load a simple
KML point file with the Google Maps Javascript API 3. I've been
searching for answers all week.

My question is; having loaded a simple instance of google maps on my
website, how can I simply add a KML layer from my server? I'm dying
here!

Santiago Nieto Carrera

unread,
May 28, 2010, 3:40:35 AM5/28/10
to Google Maps JavaScript API v3
Hi:

In your code:
var atlantaKML = new google.maps.KmlLayer('Streets.kml');
var fultonKML = new google.maps.KmlLayer('fulton.kml');

directions to the KML must be absolute and a server that is public.
Does not work with local KML files.

I hope it will help you

dcremo

unread,
May 28, 2010, 4:46:19 AM5/28/10
to Google Maps JavaScript API v3
Hi,
if the files are stored in the same directory of the main html page,
you can obtain the correct URL to your KML files adding the complete
URL (see below). The KML data will be loaded by the a server on google
side and not (directly) by the browser, therefore you cannot see it
while working in local deployments (localhost) but only in a public
site deployment.

Hope it helps,
Davide


*****************************************

var atlantaKML = new google.maps.KmlLayer(getBaseURL()+ '/
Streets.kml');
var fultonKML = new google.maps.KmlLayer(getBaseURL()+ '/
fulton.kml');


function getBaseURL ()
{
// Get document base path
documentBasePath = document.location.href;
if (documentBasePath.indexOf('?') != -1)
documentBasePath = documentBasePath.substring(0,
documentBasePath.ind\
exOf('?'));
documentBasePath = documentBasePath.substring(0,
documentBasePath.lastIndexOf\
('/'));
return( documentBasePath );
}
*****************************************

On May 28, 9:40 am, Santiago Nieto Carrera
> > </html>- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages