adafruit/Adafruit_GPS

parseLatDir and parseLonDir difference

loky32 opened this issue · 2 comments

Hi, I write because found a difference between this two functions that need similar treatment:

bool Adafruit_GPS::parseLatDir(char *p) {
if (p[0] == 'S') {
lat = 'S';
latitudeDegrees *= -1.0f;
latitude_fixed *= -1;
} else if (p[0] == 'N') {
lat = 'N';
} else if (p[0] == ',') {
lat = 0;
} else {
return false;
}
return true;
}

bool Adafruit_GPS::parseLonDir(char *p) {
if (!isEmpty(p)) {
if (p[0] == 'W') {
lon = 'W';
longitudeDegrees *= -1.0f;
longitude_fixed *= -1;
} else if (p[0] == 'E') {
lon = 'E';
} else if (p[0] == ',') {
lon = 0;
} else {
return false;
}
}
return true;
}

My question is, ¿Why in latitude the condition (if (!isEmpty(p))) is not requiered?
I think that this is a problem because when the value is not present, if you are in the south of Ecuador your latitude value can change of sign.

Good catch! Coordinates always arrive as DDMM.mmmm,S for a southern latitude, so it should always find an S and does in my tests. In any case I hope it will soon be moot, as parseCoord() will replace all four lat lon in the pending pull request.

The new parseCoord() function explicitly tests that the direction field is not empty, that the direction field is one of N, E, S, W, and that the magnitude of the angle agrees with the direction. #113 was merged about an hour ago, so the issue is solved. Thanks for the input!