Using locally stored KML file with Google Maps API.

2,764 views
Skip to first unread message

Shreyas Shinde

unread,
Oct 3, 2012, 6:30:55 AM10/3/12
to kml-support-g...@googlegroups.com
Hi, I am using a locally stored KML file. I have created this using Google Maps' Create Map finctionality. I just wanted to load this file using 'google.maps.KmlLayer' in Google Maps API V3, like, 
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
        var ctaLayer = new google.maps.KmlLayer('C:/Documents and Settings/shrshi1/Desktop/GoogleMaps/KMLs/Chicago1.kml', {preserveViewport : true});
ctaLayer.setMap(map);

This loads the map, but does not show any of the placemarks/markes in the related KML file. Any help regarding this? Following is my KML file:

<?xml version="1.0" encoding="UTF-8"?>
<Document>
  <name>Chicago</name>
  <description><![CDATA[Chicago Sample Map]]</description>
  <Style id="style2">
    <IconStyle>
      <Icon>
      </Icon>
    </IconStyle>
  </Style>
  <Style id="style1">
    <IconStyle>
      <Icon>
      </Icon>
    </IconStyle>
  </Style>
  <Placemark id="ID1">
    <name>Chicago Placemark</name>
    <description><![CDATA[Chicago1]]</description>
    <styleUrl>#style2</styleUrl>
    <Point>
      <coordinates>-87.626953,41.883877,0.000000</coordinates>
    </Point>
  </Placemark>
  <Placemark id="ID2">
    <name>West Chicago</name>
    <description><![CDATA[West Chicago1]]</description>
    <styleUrl>#style1</styleUrl>
    <Point>
      <coordinates>-88.218842,41.910454,0.000000</coordinates>
    </Point>
  </Placemark>
</Document>
</kml>

barryhunter (KML Guru)

unread,
Oct 3, 2012, 7:35:14 AM10/3/12
to kml-support-g...@googlegroups.com


        var ctaLayer = new google.maps.KmlLayer('C:/Document

That can't work. 

It will only work with public urls. Must begin with http:// or https:// and be accessible publically.

The KML is actully fetched by a Google server, do it needs to be able to fetch teh KML from a public server.  

Rossko

unread,
Oct 5, 2012, 4:27:25 AM10/5/12
to KML Developer Support - Getting Started with KML
> I just wanted to load this file using
> 'google.maps.KmlLayer' in Google Maps API V3

As Barry says, you can't.

You can load local KML by using instead an add-on script like GeoXML3,
but performance may suffer for complex KML.
Reply all
Reply to author
Forward
0 new messages