Thursday, April 8, 2010

Latitude/Longitude Converter Class Library

A few weeks ago I found an old photograph taken while we were doing a 4wd tour on the Mid North Coast of NSW. I wanted to scan and post this photo to the blog along with a Google Maps location.

The issue with this was I only had a rough idea where the photo was taken. During this 4wd tour we followed the directions in a printed book. This was 10 years ago and we did not have the use of a GPS to record our track. All I had to go on was the directions in the book. These directions made little sense trying to follow them on Google Maps as in many cases the tracks we followed are not named or marked in Google Maps.

However, the book did give GPS co-ordinates for key points on the tracks (major intersections or landmarks). I decided these could be used to provide a rough path followed and allow me to get my bearings while trying to follow the directions on Google Maps.

Once I tried to plot each of these points in Google Earth I realised it would be a slow process to import each of these points. An easier way would be to create a KML file of the points and load that into Google Earth. I had already written some code to produce a KML file of points from a CSV file so it was just a matter of loading the GPS co-ordinates into the CSV file and running the program.Unfortunately, KML files need GPS co-ordinates in Decimal Degrees and all my co-ordinates were in Degrees, Minutes and Seconds.

At this point I could have used any number of web based conversion pages to convert each co-ordinate manually. Instead, I decided to write a JAVA class library to convert co-ordinates between Degrees, Minutes and Seconds and Decimal Degrees.

The code was reasonably simple but as I had not been able to find an equivalent class on the net I decided that I would try to make it as versatile as possible with the aim to releasing it onto the web for anybody to use. It would also be a good learning exercise for me as I have created a Java class library previously.

After a weeks worth of coding I have now got the library to the point that I feel comfortable releasing a alpha version of the library to the net. There is a simple tutorial available and I am currently developing the Javadocs to go with the library.

Eventually, I will also post the source under an open source license to allow others to build or improve the library.