Rotate North?

36 views
Skip to first unread message

netski

unread,
Jun 22, 2009, 5:03:41 PM6/22/09
to KML Developer Support - Google Earth Plug-in
Hello,

I was wondering if there is anyway to rotate the earth on demand so
north is pointing to the right?

Can anyone provide a brief example, or a function I should look at?

Cheers,
Timothy

fraser (Earth API Guru)

unread,
Jun 22, 2009, 9:59:40 PM6/22/09
to KML Developer Support - Google Earth Plug-in
Hi Timothy,

The standard Api features you would use are either the LookAt or the
Camera.
See http://code.google.com/apis/earth/documentation/reference/interface_kml_look_at.html
And http://code.google.com/apis/earth/documentation/reference/interface_kml_camera.html

Both these objects provide the setHeading() method which can be used
to orientate the direction in degrees.
http://code.google.com/apis/earth/documentation/reference/interface_kml_camera.html#c8f66207d5c98cdce30a3143192def54

For both the Camera and LookAt the default heading setting is 0.
This equates to North to the top of the screen, the possible valid
values range from 0 to 360 degrees.
With this in mind if you want 'North' to be pointing 'Right' then you
want to be 'looking West'.

-------------------------------------------------
var lookAt = ge.getView().copyAsLookAt
(ge.ALTITUDE_RELATIVE_TO_GROUND);
// 0:North, 90:East, 180:South, 270:West
lookAt.setHeading(270); // West to the top
ge.getView().setAbstractView(la);
-------------------------------------------------

Hope that helps.

F.

netski

unread,
Jun 23, 2009, 9:17:32 AM6/23/09
to KML Developer Support - Google Earth Plug-in
Thanks for the response fraser, this is my example and it doesn't
appear to be working?

----------

<html>
<head>
<script type="text/javascript" src="http://maps.google.com/maps?
file=api&amp;v=2&amp;key=ABQIAAAAcJWbR_Hto-
MrH2bLVXT0ThQm8UbzhK9Svme3qXL22WXRyK5piBQOBCD8s1EACME1JW9_jMoq_Xbyrg"></
script>
<script type="text/javascript">
<!--///
var map;
var ge;

function init() {
map = new GMap2(document.getElementById('canvas'));

map.addMapType(G_SATELLITE_3D_MAP);
map.setMapType(G_SATELLITE_3D_MAP);

map.setCenter(new GLatLng(37.4328, -122.077), 13);

map.getEarthInstance(function(object) {
ge = object;

var lookAt = ge.getView().copyAsLookAt
(ge.ALTITUDE_RELATIVE_TO_GROUND);

// 0:North, 90:East, 180:South, 270:West
lookAt.setHeading(270); // West to the top

ge.getView().setAbstractView(lookAt);
} );
}
-->
</script>
</head>
<body onload="init()">
<div id="canvas" style="width: 800px; height: 600px;">

</div>
</body>
</html>

----------

Any suggestions?

Cheers,
Timothy

On Jun 22, 9:59 pm, fraser (Earth API Guru) wrote:
> Hi Timothy,
>
> The standard Api features you would use are either the LookAt or the
> Camera.
> Seehttp://code.google.com/apis/earth/documentation/reference/interface_k...
> Andhttp://code.google.com/apis/earth/documentation/reference/interface_k...
>
> Both these objects provide the setHeading() method which can be used
> to orientate the direction in degrees.http://code.google.com/apis/earth/documentation/reference/interface_k...

fraser (Earth API Guru)

unread,
Jun 24, 2009, 11:21:32 AM6/24/09
to KML Developer Support - Google Earth Plug-in
Hi,

Hmm there appears to be a bug of some kind in the earth/map
integration as far as I can tell.
I have made this test page to highlight the problem as I see it.

http://earthapi.googlepages.com/gemapbug.html

As you can see the 'changeHeading' method is called in the
getEarthInstanceCB method, the browser alerts "Heading: 270" but the
heading does not change.
However if you click the rotate button to call the function then the
browser alerts "Heading: 270" and the heading changes correctly. To me
it looks like the plug-in is still not fully initialized, even in the
getEarthInstanceCB method.

I have tested this on XP sp2/sp3 in FF 2/3, IE 7/8 and Chrome 2 all
with the same result.
AFAIK the Google Earth developer are still working on the earth/map
integration and this is possibly something that is to be fixed. Maybe
wait to hear back from one of the Google team for a more definitive
answer.

The only other thing I can suggest is to use a timeout to set the
heading after x seconds, to give the plug-in time to fully initialise.
Although that seems like an unreliable workaround to me...

Sorry I can't help more.

F.
> > > Timothy- Hide quoted text -
>
> - Show quoted text -

Roman N

unread,
Jun 26, 2009, 6:04:41 PM6/26/09
to KML Developer Support - Google Earth Plug-in
Hi Fraser, Timothy,

Can you try using Maps API 2.160 or later? ... google.load('maps',
'2.160')

We recently made some significant changes to Maps/Earth integration
that may have fixed this. If this is still broken in that version, can
you file a bug in the Earth API issue tracker?

Thanks! getEarthInstance has been pretty wonky when there was no Earth
instance available :-\

Roman

fraser (Earth API Guru)

unread,
Jun 27, 2009, 7:07:44 AM6/27/09
to KML Developer Support - Google Earth Plug-in
Hi Guys,

I changed over to the 2.160 Api and well around 50% of the time the
heading is set in the callback, 50% nothing happens.
To note, if the plug in has been initialised once, and then the page
is refreshed then it works more like 90% of the time.
Interestingly there is never an error, even when it fails.
I will leave the test page up and file a bug for this.

Thanks,

F.
> > > - Show quoted text -- Hide quoted text -

Roman N

unread,
Jul 6, 2009, 2:55:48 PM7/6/09
to KML Developer Support - Google Earth Plug-in
Thanks Fraser. Definitely sounds like getEarthIntance/timing
flakiness.
Reply all
Reply to author
Forward
0 new messages