How to call waypoints one at a time from list

Im working on a gps car and Im seeking the best way to type a series of waypoints(latitude and longitude) and once I achieve the barriers to the first waypoint set the next one in the list to currentwaypoint. Simple is better. I know i could write out code for each waypoint to go to 2 and 2 to 3 etc but Im sure there is a better way. Any suggestions?

I store the waypoints in an array, and simply step through the array indices.

For more informed responses, post your code using code tags.

Thank you! Follow up question can you use an array and multiply a number to every number at once. For example I'm using latitudes and longitudes so if i have 40.123456 the array named as a float only takes 40.12. I want to multiply the whole array by 10000 so that it uses 401234.56 maintaining accuracy

I tried waypointlat[]=waypointlat[]*10000;

but came up with an error. What is the proper way of accomplishing this?

the array named as a float only takes 40.12

I bet it doesn't. I expect that you are seeing only 2 decimal places when you print the values. Try

Serial.println(theFloat, 10);

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

Wow awesome thank you! and ya I figured since that was all it printed thats all it read off but either way more accuracy is better so I'm going to explore this gps library for sure!