With all these GPX recordings of routes I'm collecting, I wanted to view and compare details of past routes in a more user-friendly manner than poring through reams of XML output. The Google Maps API would be great to incorporate somehow, and it is freely available for JavaScript use. However I decided to be awkward and write a desktop application in Java. I'm figuring that I'll find some way around the problem of getting graphical map imagery later.
So far I have a small Java Swing/AWT application which reads an XML file of
GPS points from a recording of a cycle ride and displays the route in a
JPanel within a
JFrame:
There are three primary classes - quickChart which extends
JFrame, chartPanel which extends
JPanel, and gpxParser which extends
org.xml.sax.helpers.DefaultHandler.
When the
JFrame fires up, it sets the
JPanel to visible. The
JFrame also has a menu bar, with only two options at present: Open and Exit. Exit is obvious, and Open calls the
gpxParser class to read a XML document via SAX. There are 600 to 4000 points in a file, and as it walks through the XML tree
gpxParser reads each one into an
ArrayList. This array list is then passed over to the
JPanel, which iterates through them when rendering the route, and also when checking for 'mouseovers' (the point under the mouse is selected, as shown in orange on the route graphic).