Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

interactive google earth access

by Tsunami perl user (Initiate)
on Aug 21, 2019 at 14:41 UTC ( #11104818=perlquestion: print w/replies, xml ) Need Help??

Tsunami perl user has asked for the wisdom of the Perl Monks concerning the following question:

Is is possible to communicate interactively with google earth from a perl script? Specifically, 1. can I place symbols on the map, 2. have the operator hover over the symbol and get a small popup 3. click on the symbol and activate (or deactivate) some independent graphic and 4. control the map corners (expand, rotate, etc.)?

Replies are listed 'Best First'.
Re: interactive google earth access
by daxim (Curate) on Aug 21, 2019 at 15:16 UTC
Re: interactive google earth access
by haukex (Bishop) on Aug 21, 2019 at 20:01 UTC

    Yes, this is possible - see "Network Links" in the KML Tutorial and the rest of the KML docs. Here is a really simple proof-of-concept, open the generated main.kml and you should see the point hopping around the map while the script runs. This script is far from optimal, for example you should use a proper templating engine (e.g. Template) or XML::LibXML to generate the XML instead of the way I'm doing it here (regexes). You can control and adjust a lot of things in Google Earth using KML, it's too much to cover here, so see their documentation. I'm using my module File::Replace to help prevent Earth from reading the XML file while the script is writing it.

    use warnings; use 5.014; # for s///r use File::Replace qw/replace3/; use utf8; my $mainkml = 'main.kml'; my $dynkml = 'dyn.kml'; open my $fh1, '>:encoding(UTF-8)', $mainkml or die "$mainkml: $!"; print $fh1 <<'END_KML1' =~ s/__FILENAME__/$dynkml/r; <?xml version="1.0" encoding="UTF-8"?> <kml xmlns=""> <Folder> <name>Network Links</name> <visibility>0</visibility> <open>0</open> <NetworkLink> <name>Random Placemark</name> <refreshVisibility>0</refreshVisibility> <visibility>1</visibility> <open>1</open> <flyToView>1</flyToView> <Link> <refreshInterval>2</refreshInterval> <refreshMode>onInterval</refreshMode> <href>__FILENAME__</href> </Link> </NetworkLink> </Folder> </kml> END_KML1 close $fh1; print "Please open '$mainkml' in Google Earth\n"; my $run = 1; $SIG{INT} = sub { $run=0 }; my ($lat,$lon) = (52.514509,13.350103); while ($run) { my (undef,$outfh,$repl) = replace3($dynkml, ':encoding(UTF-8)'); print $outfh <<'END_KML2' =~ s/__LONLAT__/sprintf('%.6f,%.6f',$lon +,$lat)/er; <?xml version="1.0" encoding="UTF-8"?> <kml xmlns=""> <Placemark> <name>Random Placemark</name> <description>Hello, World!</description> <Point> <coordinates>__LONLAT__</coordinates> </Point> </Placemark> </kml> END_KML2 $repl->finish; sleep 1; $lat += (rand(2)-1)/1000; $lon += (rand(2)-1)/1000; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11104818]
Approved by marto
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2020-08-11 07:19 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (58 votes). Check out past polls.