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

前端 未结 1 680
眼角桃花
眼角桃花 2021-01-14 07:40

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 doe

1条回答
  •  借酒劲吻你
    2021-01-14 08:17

    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.

    0 讨论(0)
提交回复
热议问题