RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Give Your Applications Mapping Capabilities, Part 2  : Page 4

Learn to write applications that render static and real-time data positional data with Google Earth.

Displaying Real-Time Data in GE
When your application shows only static views (non-moving geographic data), you can pre-create the KML files or generate them at runtime (for example from an ASPX page), sending them to a user's browser (and thus to GE) only once; however, when you need to display non-static data (for example, the real-time position of a car), you can cause GE to reload a file repeatedly after rendering the view the first time. To do that, use the <NetworkLink> element, which as the name implies, creates a link from GE to your web server. There are several options that I encourage you to explore, but the simplest is to tell GE to reload the KML file at some specified interval. Because the data in that file can change between loads, reloading the file periodically causes GE to update the view, letting you show "moving" data without any additional user interaction.

Here's a simple <NetworkLink> example:

   <?xml version="1.0" encoding="UTF-8"?>
   <kml xmlns="http://earth.google.com/kml/2.2">
       <name>Network Links</name>
       <description>Network link</description>
         <name>Space Shuttle Current Position</name>
         <description>Here's where the Space Shuttle is now
As you can see, <NetworkLink> is basically just a pointer to a remote KML file with some ancillary information (name, description, refresh interval, etc.). The example above causes GE to load the linked KML file from the location specified in the <href> tag, and subsequently refresh it according to the <refreshInterval> duration—every 10 seconds in this example.

The <flytoView> element causes GE to fly to the view position specified by the root element in the linked file. This is very important because it lets you download the file, show its content, and move the user perspective (the "camera") to that position. If you set <flytoView> to 0 (false), and GE isn't already showing a view that includes the location of the downloaded data, users will not see the downloaded data until they manually move the view so the location becomes visible. The <refreshVisibility> element controls whether GE should apply the view settings in the downloaded KML each time it refreshes the file, or whether it should maintain user control, letting users change the view however they like. In the latter case, GE maintains the user-controlled view when it reloads the KML file.

The <refreshMode> element sets the refresh mode policy. Besides the onInterval mode used here, other available modes are onChange (when link parameters change), and onExpire (refresh when an expiration time is reached, which can be the HTTP max-age header).

Figure 3. Flight Tracking: The lines track the flight patterns of aircraft near New York City's JFK Airport.
Using this technique you can collect real-time positional data, write it to a KML file, and publish it on the web. Typically, you create a main KML file where the <NetworkLink> points to a secondary KML file that you'll create dynamically with the updated real-time positional data.

This technique lets you develop near-real-time applications. For example fboweb.com provides the ability to track flights online (see Figure 3).

Google Earth is a powerful and customizable 3D earth-rendering engine. Using its XML format, KML, you can create exciting applications that show maps and other geographical views, you can make those available on the web, and you can update them to display real-time data.

Bruno A. Zambetti is founder of Huge! srl, an Italy-based company specializing in Internet and distributed solutions. He is a .NET Architect, a Fortinet-certified network specialist, and has authored several articles on .NET and web infrastructures.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date