I am using SIM7600 Module, after executing "AT+CGPSINFO" this command getting location in following format, Also I have included TinyGPS++ library & used "gps.encode" function to convert coordinates of lat long but that function is not working.
Hi, thanks for your reply. Latitude & longitude is getting you can see in the response which I posted but that format is different, degrees & minutes parameter is also included in the latitude & longitude, I want to remove those parameters (degrees & minute value) is there any available function?
Its is the standard GPS NMEA format, I dont myself know of a ready made function to convert that, most GPS libraries will likley throw it out, they expect a full GPS NMEA sentence with checksum on the end.
However given that the format is;
DDMM.MMMMMMMM if you extract that from the buffer as a number then some sums will allow you to convert it in decimal degrees for instance.
Its effectivly the degrees digits then the minutes as a decimal, 0 to 59.99999999.
I wrote this function to convert a GPS latitude or longitude character string to degrees x 10^6, since with Arduino, 32 bit float variables cannot be used to store GPS coordinates accurately.
//
// decode individual NMEA lat/lon character strings in format DDDMM.MMMMM
// result is returned as long integer as degrees*10^6
// p is pointer to character string to be converted.
//
long parse_degrees(char* p) {
char* minutes;
char deg[]={0,0,0,0}; //up to 3 digits character string for integer degrees
double x;
long d;
if (strlen(p) == 0) return 0L; //invalid input string
if ((minutes = strchr(p,'.')) == NULL) return 0L; //'.' not found, invalid
minutes -= 2; //back up pointer to include two digits of minutes+decimal fraction
x = strtod(minutes,NULL); //make into double
memcpy(deg,p,minutes-p); //copy degrees, works OK with zero length string
d = strtol(deg,NULL,10)*1000000UL; //degrees to long int
d += (long)(x*16666.667 + 0.5); //*1.e6/60. add in minutes
return d;
}
jremington:
I wrote this function to convert a GPS latitude or longitude character string to degrees x 10^6, since with Arduino, 32 bit float variables cannot be used to store GPS coordinates accurately.
//
// decode individual NMEA lat/lon character strings in format DDDMM.MMMMM
// result is returned as long integer as degrees10^6
// p is pointer to character string to be converted.
//
long parse_degrees(char p) {
char* minutes;
char deg[]={0,0,0,0};
double x;
long d;
if (strlen(p) == 0) return 0L; //invalid input string
if ((minutes = strchr(p,'.')) == NULL) return 0L; //'.' not found, invalid
minutes -= 2; //back up pointer to include two digits of minutes+decimal fraction
x = strtod(minutes,NULL); //make into double
memcpy(deg,p,minutes-p); //copy degrees, works OK with zero length string
d = strtol(deg,NULL,10)1000000UL; //degrees to long int
d += (long)(x16666.667 + 0.5); //*1.e6/60. add in minutes