Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.

Adafruit Ultimate GPConvert coordinates to decimal formatS F

Good morning. The plate "Adafruit Ultimate GPS FeatherWing MTK3339"
It gives me the coordinates in this format: 4151.0869N and 214.37690E. I need the conversion to decimal format: 41.8537250 and 2.2391250.

I have made a function but it is little optimized and uses a lot of memory. Does anyone have an optimal function to do the transformation?
I attach the code of my function.
Thank you.

Code: Select all | TOGGLE FULL SIZE
`...      LAT = 0;   //LAT = 4151.2124;        LON = 0;   //LON = 214.3523;      LAT = GPS.latitude;      LON = GPS.longitude;      if ((int)GPS.fixquality < 1 )        {        goto Error;          }      if (LAT > 8999)         {        LAT=4151.1962;        goto Error;        }        if (LON > 999)   //aquesta condicio no es bona !!!        {        LON=213.9104;        goto Error;        }       ftoa(strLat,LAT, 4);      ftoa(strLon,LON, 4);      LatLon=1;       if (GPS.lat == 78 )  //LAT N nord, ascii N = 78        {          LatconvertMinSecDeg(strLat,0);        }      else         {        LatconvertMinSecDeg(strLat,1);  //LAT S              }      LatLon=2;       if (GPS.lon == 69)  //LON  E Sud, ascii E = 69         {         LatconvertMinSecDeg(strLon,0);            }      else         {          LatconvertMinSecDeg(strLon,1);  //LON W        }...void LatconvertMinSecDeg(char *DecMinuts, int PosNeg)    //Decimal Degrees = degrees + (minutes/60) + (seconds/3600){  //4151,1962N = 41+(51,1962 / 60) = 41.85327  //213,9163E = 2+(13,9163 / 60) = 2.23193  float DDDD = 0;  float MMMM = 0;  float Total = 1;   int DD = 0;  int RM = 0;  char *s;  int aa=0;  delay(500);  s = strtok( DecMinuts, ".");  while (s!=NULL)   {    if (aa==0)    {    DDDD = atol(s);      aa=1;      }    else    {    MMMM = atol(s);      }    s=strtok(NULL, ".");  }  DD = DDDD / 100;  RM = fmod(DDDD, 100);      if (PosNeg == 1)    {    Total = -1;      }  Total = Total * (DD+((RM + (MMMM / 10000))/60));   String Var;  //Var = floatToString(Total,10,9,false);  Var = floatToString(Total,10,8,false);  if (LatLon == 1) Var.toCharArray(strLat, Var.length());  if (LatLon == 2) Var.toCharArray(strLon, Var.length());  //pasem de String a Char     //strcat(strLat, "41.85327");   //strcat(strLon, "2.23193"); }String floatToString( float n, int l, int d, boolean z){ char c[l+1]; String s; dtostrf(n,l,d,c); s=String(c); if(z) { s.replace(" ","0"); } return s;}`

JoanCS

Posts: 29
Joined: Thu May 07, 2020 12:43 pm

Re: Adafruit Ultimate GPConvert coordinates to decimal forma

Good morning.
I have improved the function a bit and function better.

Code: Select all | TOGGLE FULL SIZE
`// Funció que converteix les coordenades que rep el GPS a "decimal degrees ***********************************************void LatconvertMinSecDeg(char *DecMinuts, int PosNeg)    //Decimal Degrees = degrees + (minutes/60) + (seconds/3600){  //4151,1962N = 41+(51,1962 / 60) = 41.85327   i 213,9163E = 2+(13,9163 / 60) = 2.23193  float DDDD = 0;  float MMMM = 0;  float Total = 1;   int DD = 0;  int RM = 0;  char *s;  int aa=0;  String Var="";  delay(200);  strcat(DecMinuts, ".");   s = strtok( DecMinuts, ".");  while (s!=NULL)   {    if (aa==0)    {    DDDD = atol(s);        aa=1;      }    else    {    MMMM = atol(s);      }    s=strtok(NULL, ".");   }  DD = DDDD / 100;  RM = fmod(DDDD, 100);      if (PosNeg == 1)    {    Total = -1;  // es que es S o W, ho passem a negatiu    }   Total = Total * (DD+((RM + (MMMM / 10000))/60));   if (LatLon == 1) dtostrf(Total, 3, 7, strLat);  if (LatLon == 2) dtostrf(Total, 3, 7, strLon);}// Fi funció que converteix les coordenades que rep el GPS a "decimal degrees *********************************************`

JoanCS

Posts: 29
Joined: Thu May 07, 2020 12:43 pm