Unable to load a local KMZ file into a browser with the google earth plugin using fetchkml function

梦想与她 提交于 2019-12-01 06:15:48

问题


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

When we try to use the Google Earth Plugin to do the same thing, it does not even return from the fetchKml function. Any special settings we need to know about to use fetchKml on a local file?

I am trying to load the file like so:

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

回答1:


This has nothing to do with the Google Earth Plugin as such, rather it is to do with the JavaScript sandbox.

Basically JavaScript has no access to the local file system - so you can't simply use a path to a local file such as you have in your code...

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

To work with local files in the browser you have a number of options.

  1. Set up a local file server and server the file over http. This is relatively easy to do in any OS. So that C:/KMLDATA/TEST.KMZ might become http://localhost/KMLDATA/TEST.KMZ

  2. Use some 'plugin' object that can access the file system. A bit more tricky and hard to get working across all browsers. Some thing like ActiveX, XPCOM, Signed Java applets, etc. I made an example of loading local .kml files into the plug-in via ActiveX - obviously it will only work in IE.

  3. Use the file api in HTML5. A lot of code and not something I have actually tried with kml. This tutorial is pretty thorough and covers most aspects well.

I would say that by far option 1 is your best bet. Setting up a local file server will allow you to load and test all your kml/kmz file easily.

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



来源:https://stackoverflow.com/questions/14613726/unable-to-load-a-local-kmz-file-into-a-browser-with-the-google-earth-plugin-usin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!