[Touch CDMA General] Shidell:
jnadke, here's the function I modified under your direction. Everything look good?

static int send_position_data (struct gps_state data)
{
static uint32_t last_fix;
static double last_lat, last_lon;
float position_delta;
uint32_t time_delta;
GpsLocation location;
char cmd[256];

// Added for deltaLatitude / deltaLongitude by Shidell
double deltaLongitude, adjLatitude, adjLongitude;

/* If the fix time hasn't changed, the kernel was probably just
* alerting us to new signal data */
if (data.time == last_fix)
return 0;

time_delta = data.time - last_fix;
last_fix = data.time;

memset(&location, 0, sizeof(location));
location.flags |= GPS_LOCATION_HAS_LAT_LONG;
location.flags |= GPS_LOCATION_HAS_ACCURACY;
location.latitude = ((double)data.lat) / 180000.0;
location.latitude /= correction_factor;
location.longitude = ((double)data.lng) / 180000.0;
location.longitude /= correction_factor;

/* Compute speed and bearing */
if (last_lat && last_lon) {
position_delta = location.latitude - last_lat;
position_delta *= position_delta;
position_delta += (location.longitude - last_lon) *
(location.longitude - last_lon);
position_delta = sqrt(position_delta);
/* Nautical miles per second */
location.speed = 60 * position_delta / time_delta;
/* Convert to meters per second (assuming near sea level) */
location.speed *= 1853.0;
location.flags |= GPS_LOCATION_HAS_SPEED;

if (location.longitude != last_lon) {
location.bearing = fabs(location.latitude - last_lat) /
fabs(location.longitude - last_lon);

// Previous code from srwalter:
// location.bearing = atan(location.bearing) * 360 / (6.282);

// New code from Shidell (advised by jnadke):
deltaLongitude = location.longitude - last_lat;
adjLongitude = sin(deltaLongitude) * cos(location.latitude);
adjLatitude = cos(last_lat) * sin(location.latitude) - sin(last_lat) * cos(location.latitude) * cos(deltaLongitude);
location.bearing = atan2(adjLongitude, adjLatitude) * 360 / (6.282);
// End new code

} else {
// Previous code from srwalter (removed to prevent bearing from resetting to North, this will hold last bearing):
// location.bearing = 0.0;
}

// Previous code from srwalter:
/*if ((location.latitude - last_lat) < 0) {
if ((location.longitude - last_lon) < 0) {
location.bearing += 180.0;
} else {
location.bearing += 90.0;
}
} else if ((location.longitude - last_lon) < 0) {
location.bearing += 270.0;
}
if (location.bearing >= 360.0)
location.bearing -= 360.0;*/

// New code from Shidell (advised by jnadke):
if (location.bearing < 0)
location.bearing += 360.0;
// End new code

location.flags |= GPS_LOCATION_HAS_BEARING;
#ifdef DEBUG
snprintf(cmd, 256, "echo speed %10g bearing %10g >> /sdcard/gps",
location.speed, location.bearing);
system(cmd);
#endif
}

last_lat = location.latitude;
last_lon = location.longitude;
location.accuracy = 3.0;
location.timestamp = data.time;

GPS_LOG("echo lock >> /sdcard/gps");
#ifdef DEBUG
snprintf(cmd, 256, "echo coords %10g %10g >> /sdcard/gps", location.latitude,
location.longitude);
system(cmd);
#endif

vogue_callbacks.location_cb(&location);
return 1;
}

I've attached the source. I'm spinning my wheels trying to build an ARM toolchain. If someone with more knowledge catches this and could please compile the source and post the libgps.so for testing, it'd be appreciated. :)