Monday, September 18, 2006

KML faster than GPX

When using feeds from Motionbased, the KML is 5x faster then GPX because the format is that much more compact. So if you're not using the time stamps, course heading, or speed available in the GPX feed, then using KML feed is probably a good idea.

For example:

<trkpt lat="34.1" lon="-118.2">
    <ele>141.5<ele>
    <time>2006-09-12T05:31:20-07:00</time>
    <course>0.0</course>
    <speed>3.834404896762164</speed>
</trkpt>
<trkpt lat="34.3" lon="-118.4">
    <ele>141.5<ele>
    <time>2006-09-12T05:31:21-07:00</time>
    <course>0.0</course>
    <speed>3.834404896762164</speed>
</trkpt> ...
versus
<coordinates>-118.2,34.1,411.1 -118.4,34.3,411.1 ... </coordinates>

I updated my MB/AWX mashup with this and some other improvements: http://www.bjornman.com/mb-in-awx.html

(The old mashup using GPX instead of KML is now available as http://www.bjornman.com/mb-in-awx-using-gpx.html)

The only tricky part with using KML was the irritating bug in the Mozilla/Firefox xml parser where it only gets the first 4096 character with "firstChild.data". Since an activity is often a lot longer, only the first 112 locations showed on the map. Since newer Mozilla/Firefox (though not IE) supports the "textContent" from W3C DOM Level 3, I fixed it by trying both ways of getting at the full "coordinates".

Friday, September 08, 2006

Showing MotionBased Activities in ArcWeb Explorer

Using RSS and GPX feeds from MotionBased (MB) and displaying them on maps from ArcWeb Explorer is easy. At least if you understand GeoRSS and GPX xml formats, know JavaScript, and one of the JavaScript map API's, like ArcWeb Explorer JavaScript API. The latter being free - at least for "personal, non-commercial, and non-governmental use".

What is Motionbased? ... it's a really cool "web application that translates GPS data into functional analysis and online mapping for endurance and outdoor athletes". For me that means that each time I run or bike, I bring along my GPS toy and then upload the GPS data to Motionbased when I get home.

Motionbased provides user's most recent activities in GeoRSS feeds, so it's easy to display them on the map. They also provide the activities as GPX - "the de-facto XML standard for lightweight interchange of GPS data". This makes it easy to show the exact tracks of every individual activity on a map. Whether you use the API's from Google Maps, Yahoo Maps, Ask.com or ArcWeb Explorer (AWX).

http://www.bjornman.com/mb-in-awx.html?mb=bjorn is the application I created using AWX. It reads the RSS feed with the most recent activities for a user and displays them as markers on the map. You can then click on the activities to read more about it and see the heart rate profile (if available), and to show the exact GPS route of that activity. After clicking the links above the map or the "Show Route" in the marker the GPX data will be downloaded, parsed by the browser and displayed on the map. In addition to being shown above the map, the activities are also listed inside the "Find" box. From there you can drag and drop one or more activities onto the map for it to zoom in to those. Note too that after displaying the route, the marker is updated to show elevation and heart rate profiles.

You can specify any user on the URL line, for example:

Go play!

Sunday, September 03, 2006

Parsing GeoRSS

The main problem with GeoRSS is that there are several GeoRSS standards for specifying locations. This makes it hard both for those creating the GeoRSS feeds and those doing something with those feeds. See for example Aaron's blog and the GeoRSS response.

Simple GeoRSS - http://georss.org/simple.html
<georss:point>45.256 -71.92</georss:point>

GeoRSS GML - http://georss.org/gml.html
<georss:where>
  <gml:Point>
    <gml:pos>45.256 -71.92</gml:pos>
  </gml:Point>
</georss:where>

W3C "formal" - http://www.w3.org/2003/01/geo/
<geo:Point>
  <geo:lat>55.701</geo:lat>
  <geo:long>12.552</geo:long>
</geo:Point>

W3C "casual" - http://www.w3.org/2003/01/geo/
<geo:lat>55.701</geo:lat>
<geo:long>12.552</geo:long>

So far it seems to me that the latter one - "W3C casual" is the most widely used.

I wanted to be able to map a georss feed onto a map myself (and work on my javascript skills). I could have used some of the built-in GeoRSS support, but I wanted more control of both display of the the markers as well as being able to display them outside the map.

Here's the sample javascript I came up with to parse any of these georss feeds:
var items = xmlDoc.documentElement.getElementsByTagName("item");
for( var i = 0; i < items.length; i++ )
{
  var itemtags = items.item(i).getElementsByTagName("*");
  for ( var j = 0; j < itemtags.length; j++ )
  {
    var tag = itemtags[j].nodeName;
    if (tag == 'geo:lat') {
      var lat = itemtags[j].firstChild.data;
    } else if (tag == 'geo:long') {
      var lon = itemtags[j].firstChild.data;
    } else if (tag == 'georss:point') {
      var ptArr=itemtags[j].firstChild.data.split(" ");
      var lat = ptArr[0];
      var lon = ptArr[1];
    } else if (tag == 'gml:pos') {
      var ptArr=itemtags[j].firstChild.data.split(" ");
      var lat = ptArr[0];
      var lon = ptArr[1];
    }
  }
}

[See a live sample]

It seems simple, maybe I'm missing something?