Wednesday, July 20, 2005

Controling Google Earth from JScript

Simon's recent post on controlling Google Earth from C++ got me thinking about doing the same thing in JScript. It turns out it's pretty easy: you just need set up an <object> element with the right class id. As an example, here's a small HTML document that launches Google Earth and then navigates to my house on the click of a button:

(Note that may need to enable ActiveX controls to get this to work. You'll also need to have Google Earth installed too)


<html>
<head>
<script>
function moveToCoordinates(lat, long)
{
try
{
var viewInfo = googleEarth.currentView;
viewInfo.latitude = lat;
viewInfo.longitude = long;
viewInfo.range = 1000;
viewInfo.tilt = 45;
viewInfo.azimuth = 30;
googleEarth.setView(viewInfo, 0.1);
}
catch (e)
{
alert(e.description);
}
}
</script>
</head>
<body>
<object
classid="clsid:AFD07A5E-3E20-4D77-825C-2F6D1A50BE5B"
id="googleEarth"
>
</object>
<button
onclick="moveToCoordinates(51.5256937588635, -3.20453415360346)"
>
Go To Steve's House
</button>
</body>
</html>



(Interestingly, inserting the <object> element into this post causes Google Earth to launch everytime this blog entry loads).

7 Comments:

Blogger Nicolas Hoizey said...

Doesn't work on Firefox of course... :(

7:42 AM  
Blogger danbri said...

Is this just for IE-based browsers?

3:11 AM  
Blogger Joey said...

Has anyone figured out how to call SaveScreenShot? I've tried and can't seem to get the "quality" paramter correct.

9:30 AM  
Blogger Craig Taverner said...

This does not work for me. The line 'var viewInfo = googleEarth.currentView;' always returns NULL. I have google earth plus, so I uninstalled that and reinstalled plain google earth, but the behaviour did not change. Any ideas?

11:20 AM  
Blogger ani said...

Dear Steve,
Hi I am student of BCS from india, I have project to make api which opens google earth in window. How should I do it. Please Help me . I am in very need

6:35 AM  
Blogger rduht said...

we offer wow power leveling and wow gold wow gold

5:59 PM  
Blogger gao tina said...

brautkleider But this is not entirely true. "Boy-shaped women tend to overlook what they do have. Not only can they eat what they like regardlesshochzeitskleider g√ľnstig of the calorie content, they are often blessed with lithe, long legs that hochzeitskleider 2012appear to go on forever. Their shoulder area is much like the pear's with small shoulders and a well-defined bone structure." brautkleider deutschland www.missbrautkleider.de/

11:41 PM  

Post a Comment

<< Home