Jit*_*ala 5 google-earth jquery-mobile backbone.js
如何在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">
<div id="map3d" style="height: 400px; width: 600px;"></div>
</div>
</div>
</script>
Run Code Online (Sandbox Code Playgroud)
myhtml.html
有没有什么办法解决这一问题?
任何帮助赞赏.
Earth API 与Google Earth 插件配合使用,该插件仅在 Windows 和 Mac OSX 上可用。该功能不适用于移动设备,抱歉!
如果您在 Mac 或 Windows 系统上进行测试,您应该能够使其正常工作。错误代码ERR_INVALID_DIV听起来像是没有找到map3ddiv。我会在debugger;调用之前在代码中添加一条语句google.earth.createInstance(),然后在 DOM 检查器中查看是否map3d在 DOM 中。如果该部分正常工作,它应该来自您的模板。
但是,当您尝试在移动设备上加载网站时,这对您没有帮助,因为那里没有可用的地球插件。