Search code examples
javascriptwebsocketgoogle-earth

Error calling method on NPObject exception with google earth


I'm trying to implement a Google Earth controller via Websockets.

I have a simple echo websockets server in c#, when i type a value in a textbox it just sends it back to the page (I plan to be able to directly send data from the server later).

My script to initialize google earth is pretty standard and works:

    <script type="text/javascript">

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

function init() {
  google.earth.createInstance('map3d', initCallback, failureCallback);
  StartServer();
}

function initCallback(instance) {
  ge = instance;
  ge.getWindow().setVisibility(true);

  // add a navigation control
  ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);

  // add some layers
  ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
  ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
}

function failureCallback(errorCode) 
{

}
</script>

(ge variable) is just the google earth instance.

Now in my server code, if I do:

            ws.onmessage = function (evt) 
        {
            inc.innerHTML += evt.data + '<br/>';
            var lookAt =              ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
            lookAt.setLatitude(lookAt.getLatitude() + 10);
            lookAt.setLongitude(lookAt.getLongitude() + 20);
            ge.getView().setAbstractView(lookAt);
        };

Everything works (earth rotates a tiny bit).

Now if I do:

            ws.onmessage = function (evt) 
        {
            inc.innerHTML += evt.data + '<br/>';
            var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
            lookAt.setLatitude(lookAt.getLatitude() + evt.data); //Here i try to use the data received
            lookAt.setLongitude(lookAt.getLongitude() + 20);
            ge.getView().setAbstractView(lookAt);
        };

I get exception : Error calling method on NPObject

I tried to split string, convert to number, but always get the same error.

inc.innerHTML += evt.data + '<br/>';

always works tho.

EDIT:

I also tried : var i = parseInt(d); //Works but then when i call l lookAt.setLatitude(i); //Exception

Any help appreciated


Solution

  • Ok sorted, pretty stupid thing, server was sending extra characters.

    Feels a bit bad to have this generic error on parsing, having something like "string format invalid" would be bit more meaningful.