I've been trying to measure the distance between two points using tinygps++. The code is an adapted version of the device example. It is modified to work with my board, A SAMD21 mini breakout. The line for distanceBetween was added later. When I upload the code, the distance is outputed as 9404989.55
while the distance between my two points is about 30 metres, or 100 feet.
This is the code
#include <TinyGPS++.h>
//#include <SoftwareSerial.h>
/*
This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
//static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
float landingLat = 45.478922;
float landingLng = 73.627075;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
//SoftwareSerial ss(RXPin, TXPin);
void setup()
{
SerialUSB.begin(115200);
Serial1.begin(GPSBaud);
while(!SerialUSB){}
while(!Serial1){}
SerialUSB.println(F("DeviceExample.ino"));
SerialUSB.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
SerialUSB.print(F("Testing TinyGPS++ library v. ")); SerialUSB.println(TinyGPSPlus::libraryVersion());
SerialUSB.println(F("by Mikal Hart"));
SerialUSB.println();
}
void loop()
{
// This sketch displays information every time a new sentence is correctly encoded.
while (Serial1.available() > 0){
if (gps.encode(Serial1.read()))
displayInfo();
}
if (millis() > 5000 && gps.charsProcessed() < 10)
{
SerialUSB.println(F("No GPS detected: check wiring."));
while(true);
}
}
void displayInfo()
{
SerialUSB.print(F("Location: "));
if (gps.location.isValid())
{
SerialUSB.print(gps.location.lat(), 10);
SerialUSB.print(F(","));
SerialUSB.print(gps.location.lng(), 10);
SerialUSB.print(F(", Distance to point: "));
SerialUSB.println(TinyGPSPlus::distanceBetween(gps.location.lat(), gps.location.lng(), landingLat, landingLng));
}
else
{
SerialUSB.print(F("INVALID"));
}
SerialUSB.print(F(" Date/Time: "));
if (gps.date.isValid())
{
SerialUSB.print(gps.date.month());
SerialUSB.print(F("/"));
SerialUSB.print(gps.date.day());
SerialUSB.print(F("/"));
SerialUSB.print(gps.date.year());
}
else
{
SerialUSB.print(F("INVALID"));
}
SerialUSB.print(F(" "));
if (gps.time.isValid())
{
if (gps.time.hour() < 10) SerialUSB.print(F("0"));
SerialUSB.print(gps.time.hour());
SerialUSB.print(F(":"));
if (gps.time.minute() < 10) SerialUSB.print(F("0"));
SerialUSB.print(gps.time.minute());
SerialUSB.print(F(":"));
if (gps.time.second() < 10) SerialUSB.print(F("0"));
SerialUSB.print(gps.time.second());
SerialUSB.print(F("."));
if (gps.time.centisecond() < 10) SerialUSB.print(F("0"));
SerialUSB.print(gps.time.centisecond());
}
else
{
SerialUSB.print(F("INVALID"));
}
SerialUSB.println();
}
This is a section of the output from the Serial monitor
Location: 45.4790165000,-73.6271450000, Distance to point: 9404989.83
Date/Time: 2/5/2019 02:06:03.00
Location: 45.4790165000,-73.6271450000, Distance to point: 9404989.83
Date/Time: 2/5/2019 02:06:03.00
Location: 45.4790165000,-73.6271450000, Distance to point: 9404989.83
Date/Time: 2/5/2019 02:06:03.00
Location: 45.4790165000,-73.6271450000, Distance to point: 9404989.83
Date/Time: 2/5/2019 02:06:03.00
Location: 45.4790180000,-73.6271450000, Distance to point: 9404989.68
Date/Time: 2/5/2019 02:06:04.00
Location: 45.4790180000,-73.6271450000, Distance to point: 9404989.68
Date/Time: 2/5/2019 02:06:04.00
Location: 45.4790180000,-73.6271450000, Distance to point: 9404989.68
Date/Time: 2/5/2019 02:06:04.00
Location: 45.4790180000,-73.6271450000, Distance to point: 9404989.68
Date/Time: 2/5/2019 02:06:04.00
Location: 45.4790180000,-73.6271450000, Distance to point: 9404989.68
Date/Time: 2/5/2019 02:06:04.00
Location: 45.4790180000,-73.6271450000, Distance to point: 9404989.68
Date/Time: 2/5/2019 02:06:04.00
Location: 45.4790180000,-73.6271450000, Distance to point: 9404989.68
Date/Time: 2/5/2019 02:06:04.00
Location: 45.4790180000,-73.6271450000, Distance to point: 9404989.68
Date/Time: 2/5/2019 02:06:04.00
Location: 45.4790180000,-73.6271450000, Distance to point: 9404989.68
Date/Time: 2/5/2019 02:06:04.00
Location: 45.4790183330,-73.6271446670, Distance to point: 9404989.63
Date/Time: 2/5/2019 02:06:05.00
Does anyone know why this is happening?