Search code examples
javascriptgoogle-chromegoogle-earthgoogle-earth-plugin

debugging google earth pluggin with chrome


I am developing a web application with google earth pluggin, on windows 7. I have notices that when I am printing earth objects to the chrome console (for deguggin and code checks) the objects are empty ( looks like "Object {} "). I couldn't find the reason after much googling.. Can anyone help me? Thank you!

Update: Here is the code I am running. I need help, it is impossible working without debugging..

<!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>

Everithing works, and I can see the map, but the result in the console:

{}
0% Object {}
function parseKml() { [native code] } 

Solution

  • You could either try to convert the object to JSON first. e.g.

    console.log(JSON.stringify(obj, null, 4));

    Or else use %O to force the format of the value as an expandable JavaScript object. e.g.

    console.log('%O', obj);

    Failing that output values rather than objects. e.g.

    console.log(ge.getPluginVersion()); not console.log(ge);

    EDIT

    Based on your code that is what you would expect to see. You should log the values you are interested in as I mentioned in the last example. e.g.

    console.log(ge.getPluginVersion()); not console.log(ge);

    You can also test to see what an API object is at runtime by calling getType. e.g.

    console.log(ge.getType()); // GEPlugin

    You can also test to see if an API object has a property/method at runtime using in. e.g.

    console.log('createPlacemark' in ge) // true

    To help you can always use the Google Earth API Reference if you want to know what properties and methods an API object has, or you could even open the object in something like visual studios object browser.