Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to add kml to openlayers and i am getting error in firebug

  a is undefined: Line 92 openlayers.js

here is my code :

<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>OpenLayers Basic Single WMS Example</title>

<script src="OpenLayers-2.12/lib/OpenLayers.js"></script>
<script type="text/javascript">
    var map, layer;
    function init(){
        map = new OpenLayers.Map( 'map' );
        layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
            {layers: 'basic'} );

        var kml =  new OpenLayers.Layer.Vector("KML", {
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.HTTP({
                url: "data/carmax.anand.kml",
                format: new OpenLayers.Format.KML({
                    extractStyles: true, 
                    extractAttributes: true
<body onload="init()">
<div id="map" class="smallmap" style="height:512px; width:512px"></div>
share|improve this question
I would go debugging into the line in your javascript that causes the error - try firebug or similar. I don't think its the cause of the error, but mind the invalid comma after extractAttributes: true. – Chau Jan 4 '13 at 9:06
Use <script src="OpenLayers-2.12/lib/OpenLayers.js"></script>, this show which is the failing component. – xamamano -jorix- Jan 4 '13 at 9:08
@ chau : thank you for pointing invalid comma and yes I am using firebug, which is only giving me this scripting error. @jorix : I used lib/openlayers.js and got this error : node is undefined : Line 625 – apaleja Jan 4 '13 at 9:33
@anand In which js file? – xamamano -jorix- Jan 4 '13 at 10:34
Is a error on lib/OpenLayers/Renderer/Elements.js, It can be an impropriety in the kml response, you can show a kml response from your server? – xamamano -jorix- Jan 4 '13 at 10:49

Your code is correct, I've tried to read examples/kml/sundials.kml and no error. Can be a problem is the xml response.

NOTE: Remove the comma after extractAttributes: true, this causes problems with IE.

Use to see a more specific error.

share|improve this answer

You have wrongly defined height and width of your map div. Change it to the following:

<div id="map" class="smallmap" style="height:512px; width:512px"></div>

This should work for the wms layer, you have added.

share|improve this answer
It is still giving same error in firebug – apaleja Jan 4 '13 at 9:29
As answered by xamamano, I have also tried with the local KML file. It is working. So there may be error in your kml file. You can check it through importing your KMl into Google Earth. – thelastray Jan 4 '13 at 10:42
I can open my kml with Google earth without any problem. – apaleja Jan 4 '13 at 12:26

If anyone else experiences same error I suggest adding maxExtent to OpenLayers.Map() options.

share|improve this answer
Welcome to GIS SE! Would you be able to expand upon your answer, because it was flagged up as low quality due to its length, please? – PolyGeo Sep 24 '13 at 21:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.