1

Here is my problem: i want to use a kml file from my local server but it doesn't work.

here is my code :

function initialize() {
  var chicago = new google.maps.LatLng(48.807,2.137);
  var mapOptions = {
    zoom: 11,
    center: chicago
  }

  var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

  var ctaLayer = new google.maps.KmlLayer({
    url: '78.kml'
  });
  ctaLayer.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initialize);

i tried my kml file on this web site and it's work fine

enter image description here

now thats work with this code :

<script type="text/javascript" src="http://geoxml3.googlecode.com/svn/branches/polys/geoxml3.js"></script>
        <script type="text/javascript">
            function initialize() {
  var chicago = new google.maps.LatLng(48.807,2.137);
  var mapOptions = {
    zoom: 11,
    center: chicago
  }
  var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var myKmlOptions = {
        preserveViewport: true,
        suppressInfoWindows: true
    }
var myParser = new geoXML3.parser({map: map});
myParser.parse('78.kml');
  //var ctaLayer = new google.maps.KmlLayer("http://localhost/monDossier/78Yvelines.kml",{color:"#4385F1" } );
  //ctaLayer.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initialize);
        </script>
Nadk
  • 173
  • 2
  • 3
  • 9

1 Answers1

3

No (at least not with KmlLayer), KML URLs must be publicly available. localhost is not publicly available.

from the documentation

displayed on a map using a KmlLayer object, whose constructor takes the URL of a **publicly accessible KML** or GeoRSS file.

You can use a third party parser like geoxml3 or geoxml-v3 which render KML as native Google Maps Javascript API v3 objects, but will have performance issues for complex KML.

geocodezip
  • 158,664
  • 13
  • 220
  • 245