无法使用fetchkml函数使用google Earth插件将本地KMZ文件加载到浏览器中 [英] Unable to load a local KMZ file into a browser with the google earth plugin using fetchkml function

查看:151
本文介绍了无法使用fetchkml函数使用google Earth插件将本地KMZ文件加载到浏览器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个KMZ文件可以很好地加载到Google Earth Desktop应用程序中.没有错误.

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

当我们尝试使用Google Earth插件执行相同的操作时,它甚至没有从fetchKml函数返回.我们需要了解在本地文件上使用fetchKml的任何特殊设置吗?

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 */ });

推荐答案

这与Google Earth插件无关,而是与JavaScript沙箱有关.

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

基本上,JavaScript无法访问本地文件系统-因此,您不能像使用代码中那样简单地使用本地文件的路径...

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. 设置本地文件服务器,并通过http服务器文件.这是 在任何操作系统中都相对容易实现.这样C:/KMLDATA/TEST.KMZ可能 成为http://localhost/KMLDATA/TEST.KMZ

  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

使用一些可以访问文件系统的插件"对象.一点点 难以在所有浏览器上正常工作.某物 例如ActiveX,XPCOM,Java签名小程序等.我举了一个例子 通过ActiveX将本地.kml文件加载到插件中- 显然,它仅在IE中有效.

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.

在HTML5中使用文件api.很多代码,而不是我实际上在kml上尝试过的东西. 此 教程非常详尽,涵盖了很多方面.

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.

我要说,到目前为止,选项1是您最好的选择.设置本地文件服务器将使您轻松加载和测试所有kml/kmz文件.

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.

这篇关于无法使用fetchkml函数使用google Earth插件将本地KMZ文件加载到浏览器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆