Saturday, January 11, 2014

From concept to reality in 6 weeks - part 33

I am resuming where I left off yesterday with writing C# code using the Objective-C code as a reference - within a couple of hours I should be done and then I have the rest of the day to test and validate every thing is working correctly. I have a couple of missing mapping engine APIs so that may be a challenge but I will get it as close as possible. I contacted the mapping engine lead developer and sent him an email of the missing APIs. He said he would add them for me in the next couple of weeks so I will be patient in that regard and trust him since he is totally trustworthy and is a great developer. I am happy I got to know him better during this project.

My first attempt was a pretty big failure as the mapping engine displayed a spinning globe looking down from the north pole. At least I can learn something from this. I looked that up and the north pole means a location of 90° N so somehow my location is messed up. I got into the debugger and check the location value I was setting and it was way off, so much so I am do not even want to mention what the lat/long values are. OK, for the sake of confession I will say the value was (770+, 4337+) - I am pretty sure there is no planet where those values are correct. Now I get to track down what I did wrong. At least the heading value was correct at 255°, so at least something is correct. I think the best plan of action is to go line by line and recheck what I did and maybe I will find some problems. As I was creating the C# code yesterday I was wondering about the order of the points so maybe that is different from the iPad app, but that is not my immediate problem. There is no utility I can use so I just need to take some time and compare the files. I have Xcode up on my Mac and VSE on Windows and need to slowly look at the 330 lines of Objective-C code and compare it with the 291 of C# code.

The above two paragraphs describe what I was able to do in 3 hours of work time. Not that great, as I had so many distractions yesterday and fixing this task requires complete concentration. Today is yet another new day and it is pretty quiet around work so just the environment I need for this task. I have a late day meeting so yesterday and today will count for a full day's work so I am reusing this post.

Comparing the Objective-C to C# line by line did not immediately uncover any problems until I saw the line that I was using as a work around since the version of the mapping engine that I am using is missing a method I need. The version I borrowed from http://www.movable-type.co.uk/scripts/latlong.html required a closer look and then I found the major bug that was causing most of my problems. I was passing the latitude and longitude in degrees instead of radians, so that obviously is going to be bad news when calling trig functions! I moved all of the trig functions to a separate class so I don't have to remember such things ever again. Then as I inspected location values in the debugger I noticed NaN being returned, so that is pretty evil. In the approximation function I was using I was getting the evil NaN when I passed in the same location twice. That was easy to fix as I went back to original and that problem was fixed as quick as you can say "Not a Number".

Again I did not get to finish the feature I was working on but at last I fixe most of the problems and now it is working partially so it will have to wait for next week.

No comments: