I am trying to get the Google Earth callbacks to work, but they don’t seem to be firing for me. I’ve used the View Change Example at the Google Earth API site as a reference, and see no difference between it and my code… yet mine doesn’t work!
Here are the important bits of my code:
<script type="text/javascript">
var ge;
google.load("earth", "1");
function init() {
document.getElementById('map3d').innerHTML = '';
google.earth.createInstance('map3d', initCallback, failureCallback);
}
function initCallback(pluginInstance) {
ge = pluginInstance;
ge.getWindow().setVisibility(true);
// add a navigation control
ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
// Set the FlyTo speed.
ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);
// add some layers
//ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
//ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
throw (new Error("InitCallback!"));
google.earth.addEventListener(ge.getView(), 'viewchange', function () {
throw (new Error("EVENT!"));
});
}
function failureCallback(errorCode) {
}
</script>
The “InitCallback!” error is thrown properly, but I never see the “EVENT!” error thrown — no matter how much I move the globe around.
Does anyone see what I’m doing wrong? Any help is greatly appreciated!
I’m no expert on javascript stuff, but if you replace:
with an alert instead eg:
I bet you will find it will work. ie the eventListener IS working, it just doesn’t seem to like the ‘throw’ command