2

尽我所能,我似乎无法从我的公共托管网页上的 google-earth-plugin 实例访问 kml 文件。使用我可以找到的所有谷歌开发人员帮助并尝试 Fetchkml 以及 kmlNetworkLink 均未成功,我尝试以一次一步的方式解决问题并达到以下僵局:

当我指向 code.google.com 上的 kml 源时,使用以下 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 = '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 插件缩小到旧金山。但是,如果我使用 google Chrome 下载相同的 kml_example.kml 源文件,请将未修改的 kml 文件放入我的 google docs 文档空间,获取它的相关 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>

尽管 google-earth-plugin 仍然可以正确加载,但页面加载时不会访问 kml。我只会走这些极端,因为我在 google docs 中有一个 kmz 位置(在挪威),我可以通过我的 PC 上的 google Earth 客户端中的 Network Link 很好地访问它,但不会出现在 google-earth-plugin 中我尝试使用与上述相同的代码来访问它。

谁能指出我正确的方向?

这些网页位于http://geoffreychaucernm.co.uk/offlineTEST_SITE_ghp/googlemaps/googleEarth_3.htmlhttp://geoffreychaucernm.co.uk/offlineTEST_SITE_ghp/googlemaps/googleEarth_4.html

该站点托管在 1and1 Microsoft Web 服务器上。

4

1 回答 1

3

你要踢自己。

您在示例中显示的所有代码都很好。kml_example.kml简单的问题是您用于位于您的 google 文档帐户上的源文件的 url 。

https://docs.google.com/open?id=0B3kCsTNlhwBaM2I5YTk0ZjEtOGVlNS00MGU4LTk5MTgtYTUyYzQ2Mzc2Mzhl

请注意,此 URL重定向到下载页面,而不是实际的 kml 文件。您需要获取文件本身的 Uri 而不是此中间页面。

简单的解决方法是用这个替换上面的 url,它应该可以工作

https://docs.google.com/uc?id=0B3kCsTNlhwBaM2I5YTk0ZjEtOGVlNS00MGU4LTk5MTgtYTUyYzQ2Mzc2Mzhl&export=download

请注意,这会下载文件(直接链接)。

编辑:

URL和附加参数的细微变化export=download清楚

https://docs.google.com/open?id=FILE_ID

https://docs.google.com/uc?id=FILE_ID&export=download
于 2012-02-18T07:55:28.453 回答