5

我如何将 google earth API 与bone.js+jquery mobile 结合使用?

我使用backbone.js、underscore.js 和jQuery Mobile 创建了应用程序。对于谷歌地球 API,我正在使用https://developers.google.com/earth/documentation/#using_the_google_earth_api中列出的示例代码

我的模板渲染和所有其他页面工作正常但是当我在一个标签中加载谷歌地球 API 时,它没有加载并且在 js 控制台中我收到消息:“ERR_INVALID_DIV”。

Google.earth 模块从不回调 initCallback,它总是在调用 google.earth.createInstance 时调用 failureCallback。

我解释了我的应用程序的一些示例代码,因此基于此,您可能会获得我的代码结构,它可以帮助您解决我的问题。

我的js代码如下,

myjs1.js

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

function initCB(instance) {
  console.log(' init call back call ');
  ge = instance;
  ge.getWindow().setVisibility(true);
}

function failureCB(errorCode) {
    console.log(errorCode);
}

现在我的主干代码如下,

myjs2.js

WebApp.MyPage= Backbone.View.extend({

initialize:function (result) {
    this.template =_.template($('#myPage').html());
},

render:function (eventName) {
    var self = this;
    mydata = object dict of my data;
    $(self.el).html(self.template({mydata:mydata}));

    google.load("earth", "1");

    init();
    google.setOnLoadCallback(init);

}

现在我的 HTML 代码如下所示,

<script type="text/template" id="myPage">
    <div data-role="page">
        <div data-role="content">
            <div id="map3d" style="height: 400px; width: 600px;"></div>
        </div>
    </div>
</script>

我的html.html

有没有什么办法解决这一问题?

任何帮助表示赞赏。

4

1 回答 1

0

Earth API 与Google Earth Plugin一起使用,该插件仅在 Windows 和 Mac OSX 上可用。无法在移动设备上使用,抱歉!

如果您在 Mac 或 Windows 系统上进行测试,您应该能够使其正常工作。错误代码ERR_INVALID_DIV听起来好像没有找到map3ddiv。我会debugger;在调用之前在代码中添加一条语句google.earth.createInstance(),然后在 DOM 检查器中查看是否map3d在 DOM 中。如果该部分正常工作,它应该来自您的模板。

但是,当您尝试在移动设备上加载您的网站时,这对您没有帮助,因为那里没有可用的 Earth 插件。

于 2013-06-06T07:55:47.073 回答