Antenna Aligner part 2: Finding the right direction

Posted by Chris George on Simple Talk See other posts from Simple Talk or by Chris George
Published on Mon, 21 May 2012 14:57:00 GMT Indexed on 2012/05/30 16:56 UTC
Read the original article Hit count: 270

Filed under:

Last time I managed to get "my first app(tm)" built, published and running on my iPhone. This was really cool, a piece of my code running on my very own device. Ok, so I'm easily pleased!antenna aligner sketch

The next challenge was actually trying to determine what it was I wanted this app to do, and how to do it. Reverting back to good old paper and pen, I started sketching out designs for the app. I knew I wanted it to get a list of transmitters, then clicking on a transmitter would display a compass type view, with an arrow pointing the right way.

I figured there would not be much point in continuing until I know I could do the graphical part of the project, i.e. the rotating compass, so armed with that reasoning (plus the fact I just wanted to get on and code!), I once again dived into visual studio. Using my friend (google) I found some example code for getting the compass data from the phone using the PhoneGap framework.


// onSuccess: Get the current heading
//
function onSuccess(heading) {
   alert('Heading: ' + heading);
}
navigator.
compass.getCurrentHeading(onSuccess, onError);

Using the ripple mobile emulator this showed that it was successfully getting the compass heading. But it didn't work when uploaded to my phone. It turns out that the examples I had been looking at were for PhoneGap 1.0, and Nomad uses PhoneGap 1.4.1. In 1.4.1, getCurrentHeading provides a compass object to onSuccess, not just a numeric value, so the code now looks like


// onSuccess: Get the current magnetic heading
//
function onSuccess(heading) {
   alert('Heading: ' + heading.magneticHeading);
};
navigator.
compass.getCurrentHeading(onSuccess, onError);

So the lesson learnt from this... read the documentation for the version you are actually using! This does, however, lead to compatibility problems with ripple as it only supports 1.0 which is a real pain. I hope that the ripple system is updated sometime soon.

© Simple Talk or respective owner