将 kml 文件加载到网络托管页面上的 google-earth-plugin 中
尽我所能,我似乎无法从我的公共托管网页上的 google-earth-plugin 实例访问 kml 文件。使用我可以找到的所有谷歌开发人员帮助并尝试 Fetchkml 以及 kmlNetworkLink 但没有成功,我尝试以一次一步的方式解决问题,并遇到了以下僵局:
使用以下 javascript 代码当我指向 code.google.com 上的 kml 源时,有效:
google.load("earth", "1");
var ge;
function init() {
google.earth.createInstance('mapthreedee', initCB, failureCB);
}
function initCB(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);
var link = ge.createLink('');
var href = 'http://code.google.com/apis/earth/documentation/samples/kml_example.kml';
link.setHref(href);
var networkLink = ge.createNetworkLink('');
networkLink.set(link, true, true); // Sets the link, refreshVisibility, and flyToView
ge.getFeatures().appendChild(networkLink);
}
function failureCB(errorCode) {
alert("failure");
}
google.setOnLoadCallback(init);
</script>
google-earth 插件会缩小到旧金山。但是,如果我使用谷歌浏览器下载相同的 kml_example.kml 源文件,请将未更改的 kml 文件放入我的谷歌文档文档空间中,获取它的相关 id 地址并将此地址粘贴到我的网页上的 javascript 代码中(没有对代码的其他更改),如下所示:
google.load("earth", "1");
var ge;
function init() {
google.earth.createInstance('mapthreedee', initCB, failureCB);
}
function initCB(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);
var link = ge.createLink('');
var href = 'https://docs.google.com/open?id=0B3kCsTNlhwBaM2I5YTk0ZjEtOGVlNS00MGU4LTk5MTgtYTUyYzQ2Mzc2Mzhl';
link.setHref(href);
var networkLink = ge.createNetworkLink('');
networkLink.set(link, true, true); // Sets the link, refreshVisibility, and flyToView
ge.getFeatures().appendChild(networkLink);
}
function failureCB(errorCode) {
alert("failure");
}
google.setOnLoadCallback(init);
</script></code>
页面加载时不会访问 kml,尽管 google-earth-plugin 仍然正确加载。我之所以会走向这些极端,是因为我在谷歌文档中拥有一个 kmz 位置(在挪威),我可以通过我的 PC 上的谷歌地球客户端中的网络链接很好地访问该位置,但在以下情况下不会出现在谷歌地球插件中:我尝试使用与上面相同的代码来访问它。
有人能指出我正确的方向吗?
这些网页位于 http://geoffreychaucernm.co.uk/offlineTEST_SITE_ghp/googlemaps/googleEarth_3。 html 和 http://geoffreychaucernm.co.uk/offlineTEST_SITE_ghp/googlemaps/googleEarth_4.html
该网站托管在 1and1 Microsoft Web 服务器上。
Try as I might, I seem unable to access kml files from an instance of the google-earth-plugin on my publicly-hosted web page. Using all the google developer help I can find and trying Fetchkml as well as kmlNetworkLink with no success, I have tried to approach the problem in a one-step-at-a-time way and reached the following impass:
Using the following javascript code works when I point to a kml source at code.google.com:
google.load("earth", "1");
var ge;
function init() {
google.earth.createInstance('mapthreedee', initCB, failureCB);
}
function initCB(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);
var link = ge.createLink('');
var href = 'http://code.google.com/apis/earth/documentation/samples/kml_example.kml';
link.setHref(href);
var networkLink = ge.createNetworkLink('');
networkLink.set(link, true, true); // Sets the link, refreshVisibility, and flyToView
ge.getFeatures().appendChild(networkLink);
}
function failureCB(errorCode) {
alert("failure");
}
google.setOnLoadCallback(init);
</script>
The google-earth plugin zooms down to San Fransisco. However, if I download this same kml_example.kml source file using google Chrome, place the untouched kml file into my google docs document space, get the relevant id address for it and paste this address into the javascript code on my web page (with no other changes to the code at all), like so:
google.load("earth", "1"); var ge; function init() { google.earth.createInstance('mapthreedee', initCB, failureCB); } function initCB(instance) { ge = instance; ge.getWindow().setVisibility(true); ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW); var link = ge.createLink(''); var href = 'https://docs.google.com/open?id=0B3kCsTNlhwBaM2I5YTk0ZjEtOGVlNS00MGU4LTk5MTgtYTUyYzQ2Mzc2Mzhl'; link.setHref(href); var networkLink = ge.createNetworkLink(''); networkLink.set(link, true, true); // Sets the link, refreshVisibility, and flyToView ge.getFeatures().appendChild(networkLink); } function failureCB(errorCode) { alert("failure"); } google.setOnLoadCallback(init); </script></code>
No kml is accessed when the page loads, although the google-earth-plugin still loads correctly. I am only going to these extremes because a kmz location (in Norway) I have in google docs, which I can access perfectly well via Network Link in the google Earth client on my PC, does not appear in the google-earth-plugin when I try to access it using identical code to the above.
Can anyone point me in the right direction?
These web pages are at http://geoffreychaucernm.co.uk/offlineTEST_SITE_ghp/googlemaps/googleEarth_3.html and http://geoffreychaucernm.co.uk/offlineTEST_SITE_ghp/googlemaps/googleEarth_4.html
The site is hosted on a 1and1 Microsoft web server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你会踢自己的。
您在示例中显示的所有代码都很好。简单的问题是您用于位于 Google 文档帐户上的
kml_example.kml
源文件的 URL。https://docs.google.com/open?id=0B3kCsTNlhwBaM2I5YTk0ZjEtOGVlNS00MGU4LTk5MTgtYTUyYzQ2Mzc2Mzhl
请注意,此网址重定向到下载页面,而不是实际的 kml 文件。您需要获取文件本身的 Uri,而不是此中间页面。
简单的解决方法是将上面的网址替换为这个网址,它应该可以工作
https://docs.google.com/uc?id=0B3kCsTNlhwBaM2I5YTk0ZjEtOGVlNS00MGU4LTk5MTgtYTUyYzQ2Mzc2Mzhl&export=download
请注意,这会下载文件(直接链接)。
编辑:
URL 和附加
export=download
参数的细微变化明显You are going to kick yourself.
All the code you have shown in your example is fine. The simple problem is the url you are using for the
kml_example.kml
source file located on your google docs account.https://docs.google.com/open?id=0B3kCsTNlhwBaM2I5YTk0ZjEtOGVlNS00MGU4LTk5MTgtYTUyYzQ2Mzc2Mzhl
Notice this URL redirects to a download page, not to the actual kml file. You need to get a Uri for file itself not this intermediate page.
The easy fix is to replace the above url with this one and it should work
https://docs.google.com/uc?id=0B3kCsTNlhwBaM2I5YTk0ZjEtOGVlNS00MGU4LTk5MTgtYTUyYzQ2Mzc2Mzhl&export=download
Notice this downloads the file (links directly).
Edit:
The slight change in URL and additional
export=download
parameter clearly