我正在 Windows 7 上使用 google Earth 插件开发一个 Web 应用程序。 我注意到当我将地球物体打印到 chrome 控制台时(用于调试和代码检查) 对象是空的(看起来像“Object {}”)。经过多次谷歌搜索后我找不到原因。任何人都可以帮助我吗? 谢谢!
更新:这是我正在运行的代码。我需要帮助,不调试就不可能工作..
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<div id="map3d" style="height: 100%; width: 100%;"></div>
<!--nothing inside this -->
@RenderBody()
@Scripts.Render("~/bundles/jquery")
<script src="https://www.google.com/jsapi"></script>
<script>
var ge;
function init() {
google.earth.createInstance('map3d', initCB, failureCB);
};
function initCB(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
console.log(JSON.stringify(ge, null, 4));
console.log('0%', ge);
console.log(ge.parseKml);
};
function failureCB(errorCode) {
throw ("Failed to load earth plugin. Error code = " + errorCode);
};
google.load("earth", "1", { "other_params": "sensor={false}" });
google.setOnLoadCallback(init);
</script>
</body>
</html>
一切正常,我可以看到 map ,但控制台中的结果是:
{}
0% Object {}
function parseKml() { [native code] }
最佳答案
您可以先尝试将对象转换为 JSON。例如
console.log(JSON.stringify(obj, null, 4));
或者使用 %O
强制将值的格式设置为可扩展的 JavaScript 对象。例如
console.log('%O', obj);
失败时输出值而不是对象。例如
console.log(ge.getPluginVersion());
不是 console.log(ge);
编辑
根据您的代码,这就是您期望看到的内容。您应该记录您感兴趣的值,正如我在上一个示例中提到的那样。例如
console.log(ge.getPluginVersion());
不是 console.log(ge);
您还可以通过调用 getType
来测试运行时 API 对象是什么。例如
console.log(ge.getType());
//GEPlugin
您还可以使用 in
测试 API 对象在运行时是否具有属性/方法。例如
console.log('createPlacemark' in ge)
//true
为了帮助您随时可以使用 Google Earth API Reference如果您想知道 API 对象具有哪些属性和方法,或者您甚至可以在 Visual Studio 对象浏览器之类的工具中打开该对象。
关于javascript - 使用 chrome 调试 google Earth 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24838139/