What would be the best variable type for storing GPS coordinates in a C++ program? I wrote the code below just to try it out and regardless of what variable types I chose the problem persisted.
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
class Coordinate {
public:
float xcoor, ycoor;
int radius;
void set_values (float, float, int);
};
void Coordinate::set_values (float x, float y, int r){
xcoor = x;
ycoor = y;
radius = r;
}
int main (){
Coordinate test;
test.set_values (32.682633, -117.181554, 50);
cout << "coordinates: (" << test.xcoor << "," << test.ycoor << ")\n";
return 0;
}
This code outputs the values: (32.6826,-117.182)
So obviously I am losing huge amounts of precision, but is there anyway I could maintain it? I haven't done GPS coordinates before and couldn't find anyone with a similar problem. Thank you for your help.