Saturday, November 22, 2008

It all starts with the math...

Okay, maybe not, but I thought that for this project, this would be a major part of the functionality: calculating the distance between two points. How exactly do you calculate the distance between to coordinates? Well, you can use some basic math to figure it out... if the earth was flat. Then there is the spherical formula, which would be nice, if the earth was a perfect sphere. What we end up with is a spheroid (sphere flattened at the poles), and the best formula to use for this (as per my Google research) is the Haversine formula.

To use the Haversine formula, you have to make sure your coordinates are in radians, not degrees. That's simple: radians = PI / 180 * degrees. How do you go from 30° 13' 4.07" N to something the formula can use : 30.21779722222222? You parse the string. Everything is related to 1 hour. So 30 / 1 + 13 / 60 + 4.07 / 3600 gives you the 30.21779722222222 and the N gives you the sign (+). If it was South or West, it would have been negative. The formula returns miles, so if I want yards, I multiply the result by 1760 and if I want feet, I multiply by 5280.

Now that I had figured out the formulas, I set out to create a class that would handle this work. I create a class called Haversine (after the formula used) and create a Distance method that returns a double and takes in 3 parameters: Position 1, Position 2 & Distance Type. Positions are a structure containing 2 double values for latitude and longitude. I also create a method that converts degrees into radians and vice versa. The last method is parseReg which takes a string. Basically it converts a value (30° 13' 4.07" N) that is degrees, minutes, seconds & direction into a double (30.21779722222222).

To test this puppy out, I use coordinates from my favorite golf hole at NAS, Red Hole # 1. I take the coordinates of the center of the green and the coordinates of the 200 yard marker. So the center of the green's coordinates are 30 13 4.07N latitude by 81 40 58.55W longitude. The 200 yard marker's coordinates are 30 12 58.18N latitude by 81 40 57.89W longitude. Plug those in the class and I get a result of 199.951410648 yards. For golf application, I'm willing to take this as pretty accurate, especially since the coordinates for the hole were captured off of Google Earth's site, not physical reading on the course.

Well, I'm very happy with the progress made today. I have a class that can handle all the math behind calculating the distance between to points in either yards or feet. The next hard part will be to use actual satellite pictures (probably from Google Earth's site), get coordinates from all 4 corners of the picture and then be able to use those coordinates to be figure out the distance between a point on that picture and the current GPS device location. To explain, let's say I'm looking at a bird's eye view of the hole I'm on. I'm on the tee box and I want to know how far is it to reach that creek on the left. I click on the screen where I see the end of the creek on the left and based on my current coordinates and the coordinates of where I clicked, it tells me that it's 187 yards out. That's the next goal.

Until next time,

Sebastien Limoges

The code of the Haversine class is available for download below.

Thursday, November 20, 2008

First steps toward starting the Golf Mobile GPS project

Before jumping into the development, I decided to make some research as to what was needed to do such development. It was obvious that I needed Visual Studio 2005 or greater, but what else? I found that I needed Windows Mobile 6 Professional SDK (not standard if you want to use PDA phones as your target platform), ActiveSync 4.5 (Windows XP) or greater or Windows Mobile Device Center (Windows Vista). As it turns out, Windows Mobile 6 comes pre-installed (in ROM) with .NET Compact Framework 2.0 & SQL Server 2005 Compact Edition.

Note: it was recommended that you install the .NET Compact Framework 2.0 Service Pack 1, and if using Visual Studio 2005: Visual Studio 2005 Service Pack 1 and the SQL Server 2005 Compact Edition Tools for Visual Studio 2005.

Since both my development machine are Windows Vista Ultimate, I set out to download the Windows Mobile 6 Professional SDK and install it. My goal is to get this application working on my AT&T Tilt phone equiped with Windows Mobile 6.

Here are the links to the different components needed (other than Visual Studio):

Windows Mobile 6 Professional SDK Refresh
http://www.microsoft.com/downloads/details.aspx?familyid=06111a3a-a651-4745-88ef-3d48091a390b&displaylang=en

---- If Using Windows XP ----
ActiveSync 4.5
http://www.microsoft.com/downloads/details.aspx?FamilyID=9e641c34-6f7f-404d-a04b-dc09f8141141&DisplayLang=en

---- If Using Vista ----
Windows Mobile Device Center
http://www.microsoft.com/downloads/details.aspx?familyid=46F72DF1-E46A-4A5F-A791-09F07AAA1914&displaylang=en

You can read all about what is new for developers in Windows Mobile 6 at http://msdn.microsoft.com/en-us/library/bb278115.aspx#WhatYouNeedtoStartingBuildingWindowsMobile6Applications.

The download took a while (approx 1.5 hrs for 454 MB) and so did the setup. For good measures, I also downloaded the Windows Mobile 6.1 Professional Images (USA) (http://www.microsoft.com/downloads/details.aspx?familyid=3D6F581E-C093-4B15-AB0C-A2CE5BFFDB47&displaylang=en) which took about 45 mins for 272 MB.

To see if my setup is working properly, I try to run the GPS Intermediate Driver (GPSID) example (http://msdn.microsoft.com/en-us/netframework/cc719033.aspx). My first attempt ended with an error on deployment. I looked and after a few seconds of reading the error message over, I noticed that my target was Windows Mobile 6 Professional Device and not Windows Mobile 6 Professional Emulator. So I changed that and tried again. I see the app window coming up but nothing happens when I click on GPS On, which is as expected. I then go to File | Configure and set the Shared folder path to C:\Program Files\Windows Mobile 6 SDK\Tools\GPS. This allows me to see that path, and more specifically the FakeGPS cab file in there, as if it was on a Storage Card of my emulator. I then open File Explorer and navigate to the Storage Card and click on the FakeGPS.cab file to install it. I follow the prompt and when it's done, I close File Explorer. I then go to Start menu and run Fake GPS. I enable the GPS and make sure that it has the fake GPS text file data selected and then click Done. I'm back to the GPSID app and click on GPS On and voila! I see that this sample app is working and "receiving" and displaying GPS data successfully. When I close the emulator, it prompts me if I want to save the emulator state before exiting. To save the trouble of having to redo all these configuration steps, I choose Yes.

Well this concludes the setup and testing of my setup. My next step is to figure out what I want to accomplish with my application, come up with a design and start designing the framework and UI for it.

Until next time,

Sebastien Limoges

Wednesday, November 19, 2008

Golf GPS Application with Satellite imagery for Mobile Devices

This is my blog about my attempt to create a golf application that will not only give me basic numerical information of where I am in regards to the green and other obstacles, but also a satellite view of where it is I am in relation to the green and other obstacles.

Come back to see information on my progress (or lack thereof) in my attempt to complete this project.