[OpenLayers-Users] Using OpenLayers to Map Realtime Data

Christopher Schmidt crschmidt at crschmidt.net
Sat May 27 15:48:20 CDT 2006


Earlier today, I had the 'joy' of taking a plane trip from Boston to
Chicago. However, despite the cramped seat, I was able to use the time
to make a pretty neat demo of OpenLayers capabilities that I might not
otherwise have been able to.

While flying, I set my bluetooth GPS (A Royaltek RBT-3000 -- I highly
recommend this GPS, as it alwyas seems to get much better reception than
my Etrex Legend) in the window of the plane. I connected to it and
redirected the raw NMEA data to a file on the local machine.

I then created a cgi script which would return the decimal latitude and
longitude of my current location. This was actually a combination of two
scripts: I was doing this for speed, not cleanliness. 

The cgi script was simple:
#!/bin/sh
echo -e "Content-Type: text/plain\r\n\r\n"
python /Users/crschmidt/flying/lat2dec.py `tail -n 50 \
  /Users/crschmidt/flying.txt | grep "GPGGA" | tail -n 1`

"Find the last GPGGA sentence in the tracklog, and send it into
lat2dec.py" (not really appropriately named, as you'll see in a second).
The python script was designed to convert from a GPGGA sentence to a
decimal lat/lon: the code is attached.

Once I had that, I opened up my local OpenLayers instance: this
OpenLayers is specifically designed for times when I don't have internet
access, so instead of talking to the octo.metacarta.com WMS server, it
talks to localhost, and the WMS serves up a couple layers:

http://nationalatlas.gov/mld/road00l.html -- North American Roads
http://nationalatlas.gov/mld/bound0m.html -- Political Boundaries
http://mappinghacks.com/data/ -- World borders

(There may be some overlap in the second two.)

So, the next step was to add the ability to add markers based on my
current location. The code that did this is here:

function addMarker() {
  var handler = XMLrequest();
  handler.onreadystatechange=function() {
    if (handler.readyState == 4 && handler.status == 200)
      var lonlat = handler.responseText;
      lonlat = lonlat.split(',');
      if (lonlat[1]) {
        var loc = new OpenLayers.LonLat(lonlat[0],lonlat[1]);
        markers.addMarker(new OpenLayers.Marker(loc, icon));
      }
    }
  }
  handler.open("GET", "/cgi-bin/loc.cgi", true);
  handler.send('');
  setTimeout(addMarker, '1000');
}

'markers' in this case is a OpenLayers.Layer.Markers layer, and icon is
an OpenLayers.icon object.

After this, all I had to do was add a single call to addMarker() at the
end of the main init() in the example OpenLayers file, and I had a live
display of my current location on a map, moving at 450 mph.

The coolest thing about this? Even if I *had* had internet, this kind of
activity is forbidden by the ToS of the Google-Yahoo-Microsoft. This is
a hack that you would not be able to do in the current mapping APIs.

Say what you will, but this kind of thing is the reason that I want to
have OpenLayers take over the world: I want to be able to do what I want
with my data, and get cool things out of it, withotu worrying that some
corporation will shut me down to protect their data license. I don't
need street level data for this task: free data that I can set up on my
own covers it, and provides a really nifty visual effect, without any
cost, and without worrying about licensing concerns.


If there's more details wanted, or help setting up something similar,
feel free to ask/reply and I can go into more detail.

-- 
Christopher Schmidt
Web Developer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lat2dec.py
Type: text/x-python
Size: 685 bytes
Desc: not available
Url : http://mailman-viper.python-hosting.com/pipermail/users/attachments/20060527/f8e87445/lat2dec.py


More information about the Users mailing list