Failed to load local KMZ file into browser with google earth plugin using fetchkml function

We have a KMZ file that loads into the Google Earth Desktop app just fine. No mistakes.

When we try to use the Google Earth plugin to do the same, it doesn't even return from the function fetchKml

. Any special settings we need to know to use fetchKml

in a local file?

I am trying to download a file like this:

// Where 'ge' is the Google Earth Plugin
var href = 'C:/KMLDATA/TEST.KMZ';
google.earth.fetchKml(ge, href, function(kml) { /* do something with kml */ });

      

+3


source to share


1 answer


This has nothing to do with the Google Earth plugin per se, but is related to the JavaScript sandbox.

Basically JavaScript does not have access to the local filesystem - so you cannot just use the local file path, for example in your code ...

var href = 'C:/KMLDATA/TEST.KMZ';
google.earth.fetchKml(ge, href, function(kmlObject) { ... }

      

To work with local files in a browser, you have several options.



  • Set up local file server and server file over http. This is relatively easy to do on any OS. To C:/KMLDATA/TEST.KMZ

    becomehttp://localhost/KMLDATA/TEST.KMZ

  • Use some "plugin" object that can access the filesystem. Slightly more complex and difficult to work with in all browsers. Anything like ActiveX, XPCOM, Signed Java Applets, etc. I made an example of loading local .kml files into a plugin via ActiveX - obviously it will only work in IE.

  • Use the api file in HTML5. Lots of code, not what I really tried with kml. This tutorial is fairly thorough and covers most aspects.

I would say option 1 is your best bet. Setting up a local file server will allow you to easily download and test your entire kml / kmz file.

If this is not possible or desirable for you, then hosting the files on a public server, as others have suggested, is really the only option.

+2


source







All Articles