<?xml version="1.0" encoding="windows-1252"?>
<node id="596676" title="Perl Mongers Google Earth Tour" created="2007-01-26 01:42:51" updated="2007-01-25 20:42:51">
<type id="120">
perlmeditation</type>
<author id="366986">
brian_d_foy</author>
<data>
<field name="doctext">
&lt;p&gt;
Randal has been playing around with Aperture to organize his  photos on his MacBook then upload them to Flickr. It has a nifty feature to geotag images based on the current view in Google Earth.
&lt;/p&gt;
&lt;p&gt;
I figured that must be using AppleScript, so I tried creating a [cpan://Mac::Glue] glue for it:
&lt;/p&gt;
&lt;code&gt;
% sudo gluemac /Applications/Google\ Earth.app
&lt;/code&gt;
&lt;p&gt;
That worked. The glue isn't that interesting. I can get the data for the current view, which is what Aperture does:
&lt;/p&gt;
&lt;code&gt;
my $gEarth = Mac::Glue-&gt;new('Google_Earth');

my $reco = $gEarth-&gt;getviewinfo;
&lt;/code&gt;
&lt;p&gt;
That gives me a hash:
&lt;/p&gt;
&lt;code&gt;
        {
          'azimuth' =&gt; '1.19852752792094e-14',
          'longitude' =&gt; '-96.4999988896226',
          'distance' =&gt; '25484000',
          'latitude' =&gt; '40.4999984526947',
          'tilt' =&gt; '-1.26725225589562e-15'
        }
&lt;/code&gt;
&lt;p&gt;
I want to set the view though. But what to set it too? How about flying through all of the Perl Mongers locations? I can get those from the &lt;a href="http://www.pm.org/groups/perl_mongers.xml"&gt;Perl Mongers XML file&lt;/a&gt;. Once I extract the latitude and longitude I pass it back to &lt;code&gt;setviewinfo&lt;/code&gt;. If I wanted to get really fancy I could then use &lt;code&gt;savescreenshot&lt;/code&gt; to save the view.
&lt;/p&gt;
&lt;code&gt;
#!/usr/bin/perl

use LWP::Simple;
use Mac::Glue;

print "Downloading Perl Mongers XML file...";
my $data = get( 'http://www.pm.org/groups/perl_mongers.xml' );
$data ? ( print "done\n" ) : ( die "Could not get file!" );

# See Mac::Glue for details on creating the glue, probably:
#     gluemac /Applications/Google\ Earth.app
print "Starting Google Earth...";
my $gEarth = Mac::Glue-&gt;new( 'Google_Earth' );
$gEarth ? ( print "done\n" ) : ( die "Could not start Google Earth!" );


while( $data =~ m|&lt;group.*?&gt;(.*?)&lt;/group&gt;|gs )
	{
    # I could use an XML parser, but it's too easy to do  it myself
	my( $name, $long, $lat ) = $1 =~ m|
		&lt;name&gt;(.*?)&lt;/name&gt;
			.*?
		&lt;longitude&gt;(.*?)&lt;/longitude&gt;
			.*?
		&lt;latitude&gt;(.*?)&lt;/latitude&gt;
		|xs;
		
	print "Flying to $name\n";
	
	$gEarth-&gt;setviewinfo(
		{
		'azimuth'   =&gt; '0',
		'longitude' =&gt; $long,
		'distance'  =&gt; '4000',
		'latitude'  =&gt; $lat,
		'tilt'      =&gt; '0'
		}
		);

	sleep 15;
	}

&lt;/code&gt;
&lt;p&gt;
You might have to make that sleep a little longer if you have a slower network connection, and maybe you want to loop around the &lt;code&gt;setviewinfo&lt;/code&gt; to start farther up (that number is in meters) and zoom in.
&lt;/p&gt;
&lt;p&gt;
Have fun :)
&lt;/p&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-366986"&gt;
-- &lt;br /&gt;
brian d foy &lt;brian@stonehenge.com&gt;&lt;br /&gt;
Subscribe to &lt;a href="http://www.theperlreview.com"&gt;The Perl Review&lt;/a&gt;
&lt;/div&gt;&lt;/div&gt;</field>
</data>
</node>
