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\ Earth.app
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( '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->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 :)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.