Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Perl Mongers Google Earth Tour

by brian_d_foy (Abbot)
on Jan 26, 2007 at 06:42 UTC ( #596676=perlmeditation: print w/replies, xml ) Need Help??

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.

I figured that must be using AppleScript, so I tried creating a Mac::Glue glue for it:

% sudo gluemac /Applications/Google\

That worked. The glue isn't that interesting. I can get the data for the current view, which is what Aperture does:

my $gEarth = Mac::Glue->new('Google_Earth'); my $reco = $gEarth->getviewinfo;

That gives me a hash:

{ 'azimuth' => '1.19852752792094e-14', 'longitude' => '-96.4999988896226', 'distance' => '25484000', 'latitude' => '40.4999984526947', 'tilt' => '-1.26725225589562e-15' }

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 Perl Mongers XML file. Once I extract the latitude and longitude I pass it back to setviewinfo. If I wanted to get really fancy I could then use savescreenshot to save the view.

#!/usr/bin/perl use LWP::Simple; use Mac::Glue; print "Downloading Perl Mongers XML file..."; my $data = get( '' ); $data ? ( print "done\n" ) : ( die "Could not get file!" ); # See Mac::Glue for details on creating the glue, probably: # gluemac /Applications/Google\ print "Starting Google Earth..."; my $gEarth = Mac::Glue->new( 'Google_Earth' ); $gEarth ? ( print "done\n" ) : ( die "Could not start Google Earth!" ) +; while( $data =~ m|<group.*?>(.*?)</group>|gs ) { # I could use an XML parser, but it's too easy to do it myself my( $name, $long, $lat ) = $1 =~ m| <name>(.*?)</name> .*? <longitude>(.*?)</longitude> .*? <latitude>(.*?)</latitude> |xs; print "Flying to $name\n"; $gEarth->setviewinfo( { 'azimuth' => '0', 'longitude' => $long, 'distance' => '4000', 'latitude' => $lat, 'tilt' => '0' } ); sleep 15; }

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 setviewinfo to start farther up (that number is in meters) and zoom in.

Have fun :)

brian d foy <>
Subscribe to The Perl Review

Replies are listed 'Best First'.
Re: Perl Mongers Google Earth Tour
by Anonymous Monk on Jan 26, 2007 at 12:27 UTC
    Gee! How can you live with those '{' indentations? :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://596676]
Approved by Zaxo
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2018-03-22 07:14 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (273 votes). Check out past polls.