Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: interactive google earth access

by haukex (Archbishop)
on Aug 21, 2019 at 20:01 UTC ( [id://11104830]=note: print w/replies, xml ) Need Help??


in reply to interactive google earth access

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11104830]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 17:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found