小编Jit*_*ala的帖子

我如何使用google earth API与backbone.js + jquery mobile?

如何在backbone.js + jquery mobile中使用google earth API?

我使用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);
}
Run Code Online (Sandbox Code Playgroud)

现在我的Backbone代码如下,

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);

}
Run Code Online (Sandbox Code Playgroud)

现在我的HTML代码如下,

<script type="text/template" id="myPage">
    <div data-role="page">
        <div data-role="content"> …
Run Code Online (Sandbox Code Playgroud)

google-earth jquery-mobile backbone.js

5
推荐指数
1
解决办法
524
查看次数

标签 统计

backbone.js ×1

google-earth ×1

jquery-mobile ×1