How to call waypoints one at a time from list

A float only has ~7 significant digits, so you shouldn't print more than 5 or 6 digits after the decimal point for a lat/lon:

    Serial.println(theFloat, 6);

You can put as many as you want in the code, but only 7 will be retained for comparison. Multiplying by 10000.0 does not help.

If you need more than 7 digits, you should take a look at my NeoGPS library. It stores lat/lon as integers (internally), and they have 10 significant digits. The distance and bearing calculations maintain that precision.

To declare the array of locations, use the NeoGPS Location_t type:

NeoGPS::Location_t waypoints[] =
  {
    { 13062820, 1038322750 },
    { 13062820, 1038322750 },
    { 13023070, 1038368650 },
    { 13062820, 1038322750 },
    { 13065860, 1038328320 },
    { 12714200, 1038192080 },
    { 12480740, 1038213810 },
    { 12842550, 1038608650 },
    { 12894280, 1038465000 },
  };

These are the lat/lon values * 10000000, as 32-bit integers (not float). There's even room for another significan digit, if you can figure it out from google maps.

The basic code is like this:

      uint8_t currentWaypoint = 0;
const uint8_t LAST_WAYPOINT   = sizeof(waypoints)/sizeof(waypoints[0]); // always the correct array size

void loop()
{
  while (gps.available( gpsPort )) {
    gps_fix fix = gps.read();

    if (fix.valid.location) {

      distance = fix.location.DistanceKm( waypoints[ currentWaypoint ] );

      if (distance < 0.020) { // 20m
        currentWaypoint++;

        if (currentWaypoint == LAST_WAYPOINT)
           ; // what?
        else
           ; // head toward next waypoint?

This is from a similar discussion here. If you want to try it, NeoGPS is available from the Arduino IDE Library Manager, under the menu Sketch -> Include Library -> Manage Libraries. It's smaller, faster and more accurate than all other libraries.

Cheers,
/dev

1 Like