Assigning float to 10 decimal place for longitude,latitude

Hi,

I'm quite a novice in arduino programming. I am doing a small home project and I am using sim808 to obtain GPS data.

My question is quite simple but i can't find any solution online.

Serial.print("latitude :");
Serial.println(sim808.GPSdata.lat, 10);
Serial.print("longitude :");
Serial.println(sim808.GPSdata.lon, 10;

This code display Longitude and Latitude data on serial monitor to 10 decimal place perfectly.

But when after setting the Longitude and Latitude to float.When I use this code, I don't get a valid gps data.

Longitude = (sim808.GPSdata.lon, 10 );
Latitude = (sim808.GPSdata.lat, 10 );

Please help, Thanks.

The Arduino floating point code is only capable of support 6 or 7 digits of precision. You can print more than that, but they'll be wrong...

Longitude = (sim808.GPSdata.lon, 10 );
Latitude = (sim808.GPSdata.lat, 10 );

These statements are nonsense. When you assign a value to a variable, there is no place for you to tell it how many digits you want; the full precision is always stored:

    Longitude = sim808.GPSdata.lon;
    Serial.print(Longitude, 10);   // really only good to 6 or 7 digits, but print 10 anyway!

As it happens, C includes an obscure "comma" operator that means that

    Latitude = (sim808.GPSdata.lat, 10 );

is a legal C statement that assigns the value 10 to Latitude (which of course is not at all what you wanted.)

As westfw said, the float type only has 7 significant digits. You can print more, but the extra digits are meaningless. A float is accurate to about 1 meter, but the GPS device is only accurate to 3 meters, on a good day.

If you really want 10 digits of precision, there is a way to get the 3 extra digits of precision by using my NeoGPS library with the DFRobot SIM808 library. To make those extra location digits meaningful, you'd have to average ~30 minutes of readings. The NMEAaverage.ino example program shows one way to do that.

If you are doing distance and bearing calculations on individual readings (not an averaged location), NeoGPS calculations are more accurate at smaller distances.

Cheers,
/dev

To make those extra location digits meaningful, you'd have to average ~30 minutes of readings.

While staying still? Or while moving?

westfw, I get your point completely. I now understand the logic in the code.

/dev thanks for referring me the library, I am checking it right now.

In fact, I am using a DF robot shield sim 808 for vehicle tracking. I am uploading my GPS data, longitude, latitude and speed to Ubidots. The only difficulty is in saving accurate data.

I am using this codes

Longitude = sim808.GPSdata.lon;
Latitude = sim808.GPSdata.lat;
Speedperkm = sim808.GPSdata.speed_kph;

client.add("Longitude", Longitude);
client.add("Latitude", Latitude);
client.add("Speed per Km", Speedperkm);

The code is working fine but only GPS data of 2 decimal place is being uploaded. If data of up to 6 decimal place is uploaded then the system will more accurate.

That my problem that I am trying to solve.

That my problem that I am trying to solve.

You won't get help here posting just snippets. Post ALL of your code, so we know what a client is an what the add() method actually expects as input, and actually does with it.

PaulS:
While staying still?

Yes. The reported location "wanders" around the actual location