Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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 (Deacon) on Aug 21, 2019 at 15:16 UTC
Re: interactive google earth access
by haukex (Chancellor) 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="http://www.opengis.net/kml/2.2"> <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="http://www.opengis.net/kml/2.2"> <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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2019-09-23 09:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (279 votes). Check out past polls.

    Notices?