my arrays storing specific lat/lon are like this:
Like this:
NeoGPS::Location_t clues[] =
{
{ 1.306282, 103.832275 },
{ 1.302307, 103.836865 },
...
However...
Also, the NMEAdistance example bundled with your library notes the base coordinates as this:
NeoGPS::Location_t base( -253448688L, 1310324914L );
On the Arduino, the float type only has 6 or 7 significant digits. It is not accurate enough to distinguish between 103.832275 and 103.832832. You can put the extra digits in your code, but it's really using ~103.8322 and ~103.8238.
If you really have 9 significant digits, you have to use the integer forms of those lat/lon coordinates:
{ 12480740, 1038213810 },
You just multiple the degrees by 10,000,000. NeoGPS supports 10 significant digits, so I had to add a zero. You could provide another significant digit, if you can figure it out. NeoGPS is the only library that can use these accurate locations to calculate an accurate distance at small distances.
Here is a sketch with those coordinates:
#include <NMEAGPS.h>
NMEAGPS gps;
#define gpsPort Serial1 // BEST choice for a Mega, Leo or Due
// Next best, but requires specific pins (.g., 8&9 on an UNO):
// #include <AltSoftSerial.h>
// AltSoftSerial gpsPort;
// Third best, if specific pins can't be used:
// #include <NeoSWSerial.h>
// NeoSWSerial gpsPort( 3,4 ); // baud rate must be 9600, 19200 or 38400
// SoftwareSerial NOT RECOMMENDED
NeoGPS::Location_t clues[] =
{
{ 13062820, 1038322750 },
{ 13023070, 1038368650 },
{ 13062820, 1038322750 },
{ 13065860, 1038328320 },
{ 12714200, 1038192080 },
{ 12480740, 1038213810 },
{ 12842550, 1038608650 },
{ 12894280, 1038465000 },
};
uint8_t current_clue = 0;
uint8_t updates = 0;
float distance = 1000.0; // km
void setup()
{
Serial.begin( 9600 );
gpsPort.begin( 9600 );
}
void loop()
{
while (gps.available( gpsPort )) {
gps_fix fix = gps.read();
updates++;
if ((updates >= 6) && fix.valid.location) {
updates = 0;
distance = fix.location.DistanceKm( clues[ current_clue ] );
Serial.print( F("Distance: ") );
Serial.println(distance);
}
}
}
Of course, I have no idea how the current_clue advances through the array. Perhaps something like this:
const uint8_t CLUE_MAX = sizeof(clues)/sizeof(clues[0]);
const float CLOSE_ENOUGH = 0.005; // 5m
...
void loop()
{
...
distance = fix.location.DistanceKm( clues[ current_clue ] );
Serial.print( F("Distance: ") );
Serial.println(distance);
// distance = 0.001; // to test advancing through the clues
if (distance < CLOSE_ENOUGH) {
if (current_clue < CLUE_MAX-1) {
Serial.println( F("Next...") );
current_clue++;
} else {
Serial.println( F("Here!") );
for (;;); // hang here
}
}
Cheers,
/dev