Question

Pour tester I enregistré ce fichier html sur mon serveur. Y at-il un moyen simple d'inclure un fichier KML ou KMZ ici?

<!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&amp;v=2&amp;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.setUIToDefault();
      }
    }

    </script>   </head>   <body onload="initialize()" onunload="GUnload()">
    <div id="map_canvas" style="width: 800px; height: 600px"></div>   </body> </html>
Était-ce utile?

La solution

Essayez d'ajouter le code JavaScript suivant à votre fonction init:

var kml = new GGeoXml("http://yoururl.com/yourfile.kml");
map.addOverlay(kml)

Notez que le KML doit être une URL accessible au public, et il y a une limite de ~ 10MB:

https://developers.google.com/kml/documentation/mapsSupport

Autres conseils

Vous devez covert un LineStrings KML à un Gmap Polyligne qui impliquera un peu de manuel la manipulation de données, ou un analyseur XML.

Vous pouvez également essayer cette ligne outil de conversion .

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top