I use a u-blox gps with my arduino. I can successfully write out the value of a coordinate (lat, lng) like this: Serial.println (gps.location.lat(), 8);
but when I try to store the value with all the decimals it returns 8.00
instead of the correct coordinate + all of the 8 decimals.
This is my code:
#include "TinyGPS++.h"
#include <SoftwareSerial.h>
SoftwareSerial gpsconnection (4,3);
TinyGPSPlus gps;
void setup()
{
Serial.begin(9600);
gpsconnection.begin (9600);
}
void loop()
{
while (gpsconnection.available())
{
gps.encode(gpsconnection.read());
}
//this works and returns 8 decimals
Serial.println (gps.location.lat(), 8);
Serial.println (gps.location.lng(), 8);
//but if i try to store it like this:
double latcord = (gps.location.lat(), 8);
double lngcord = (gps.location.lng(), 8);
//it returns 8.00 on both the "latcord" and "lngcord" which is the wrong coordinate and also it doesnt return 8 decimals
Serial.println (latcord);
Serial.println (lngcord);
//if i try to convert the value to a string and then back to a double like this:
double lat = gps.location.lat();
String msgLat = String(lat, 8);
double thelat = atof(msgLat.c_str());
//with this i get the correct first two numbers out but only 2 decimals after, not 8 decimals as it should be.
Serial.println (thelat);
}