0

将 Google 地球网络链接嵌入 Blogger 时出现的奇怪问题。我正在使用的代码如下所示,但我在同一页面上获得了两个 GE 实例,一个在另一个之上。它们必须单独生成,就好像我在页面上的 div 样式中添加了一个边框,它只影响一个实例。

<div id="map3d" style="border: 4px solid silver; height: 768px; width: 1024px;"></div>

但是,如果我从页面中完全删除此代码。两种情况都消失了。

除此之外,我已经让它按我想要的方式运行。(最终)

这是我在头部的代码

<!-- Earth -->
<script src="//www.google.com/jsapi?key=mykey"></script>
<script type="text/javascript">
  var ge;
  google.load("earth", "1", {"other_params":"sensor=false"});

  function init() {
     google.earth.createInstance('map3d', initCB, failureCB);
  }

  function initCB(instance) {
     ge = instance;
     ge.getWindow().setVisibility(true);
     ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);

     var href = 'http://urltomykmz';

     google.earth.fetchKml(ge, href, function(kmlObject) {
           if (kmlObject)
              ge.getFeatures().appendChild(kmlObject);
           if (kmlObject.getAbstractView() !== null)
              ge.getView().setAbstractView(kmlObject.getAbstractView());
     });
  }

  function failureCB(errorCode) {
  }

  google.setOnLoadCallback(init);
</script>
<!-- Earth -->

感谢任何可以指出导致第二次实例的原因的人。谢谢。

4

1 回答 1

0

您必须删除处理程序init()onload的调用或调用google.setOnLoadCallback(init),否则每次调用该init函数时都会添加一个映射。

于 2014-06-24T14:59:51.627 回答