gps sim908

hey i used this code for gps sim908 ,it works but i have problem ,the location of latitude and longitude are far from my location by few KM but i want to get the exact location.

int8_t answer;
int onModulePin= 13;
int counter;
long previous;

char aux_string[30];
char data[100];
int data_size;

int x = 0;
char N_S,W_E;

char frame[200];

char latitude[15];
char longitude[15];
char altitude[6];
char date[16];
char time[7];
char satellites[3];
char speedOTG[10];
char course[10];


void setup(){
    
    pinMode(onModulePin, OUTPUT);
    Serial.begin(115200);   
    
    Serial.println("Starting...");
    power_on();
    
    delay(3000);
    
    // sets the PIN code
    //sendATcommand("AT+CPIN=****", "OK", 2000);
    //sendATcommand("AT+CPIN?", "READY", 500);
     
    delay(3000);
    
    // sets APN, user name and password
    sendATcommand("AT+CGPSPWR=1", "OK", 2000);
    sendATcommand("AT+CGPSRST=1", "OK", 2000);
    delay(1000);
    
    // waits for fix GPS
  while( (sendATcommand("AT+CGPSSTATUS?", "2D Fix", 5000) || 
           sendATcommand("AT+CGPSSTATUS?", "3D Fix", 5000)) == 0 );
        // Basic
    // Clean the input buffer
    sendATcommand("AT+CGPSINF=0", "AT+CGPSINF=0\r\n\r\n", 2000);

    counter = 0;
    answer = 0;
    memset(frame, '\0', 100);    // Initialize the string
    previous = millis();
    // this loop waits for the NMEA string
    do{

        if(Serial.available() != 0){    
            frame[counter] = Serial.read();
            counter++;
            // check if the desired answer is in the response of the module
            if (strstr(frame, "OK") != NULL)    
            {
                answer = 1;
            }
        }
        // Waits for the asnwer with time out
    }
    while((answer == 0) && ((millis() - previous) < 2000));  

    frame[counter-3] = '\0'; 
    
    // Parses the string 
    strtok(frame, ",");
    strcpy(longitude,strtok(NULL, ",")); // Gets longitude
    strcpy(latitude,strtok(NULL, ",")); // Gets latitude
    strcpy(altitude,strtok(NULL, ".")); // Gets altitude 
    strtok(NULL, ",");    
    strcpy(date,strtok(NULL, ".")); // Gets date
    strtok(NULL, ",");
    strtok(NULL, ",");  
    strcpy(satellites,strtok(NULL, ",")); // Gets satellites
    strcpy(speedOTG,strtok(NULL, ",")); // Gets speed over ground. Unit is knots.
    strcpy(course,strtok(NULL, "\r")); // Gets course

    convert2Degrees(latitude);
    convert2Degrees(longitude);
    
    
    Serial.println("*************************************************");
    Serial.print(" Longitude: ");
    Serial.println(longitude);
    Serial.print("Latitude: ");
    Serial.println(latitude);

    sendATcommand("AT+CGPSPWR=0", "OK", 2000);
    


}

void loop(){
    
}

void power_on(){

    uint8_t answer=0;
    
    // checks if the module is started
    answer = sendATcommand("AT", "OK", 2000);
    if (answer == 0)
    {
        // power on pulse
        digitalWrite(onModulePin,LOW);
        delay(3000);
        digitalWrite(onModulePin,HIGH);
    
        // waits for an answer from the module
        while(answer == 0){    
            // Send AT every two seconds and wait for the answer
            answer = sendATcommand("AT", "OK", 2000);    
        }
    }
    
}


int8_t sendATcommand(char* ATcommand, char* expected_answer1,
        unsigned int timeout)
{

    uint8_t x=0,  answer=0;
    char response[100];
    unsigned long previous;

    memset(response, '\0', 100);    // Initialize the string
    
    delay(100);
    
    // Clean the input buffer
    while( Serial.available() > 0) Serial.read();    
    
    Serial.println(ATcommand);    // Send the AT command 


    x = 0;
    previous = millis();

    // this loop waits for the answer
    do{

        if(Serial.available() != 0){    
            response[x] = Serial.read();
            x++;
            
            // check if the desired answer is in the response of the module
            if (strstr(response, expected_answer1) != NULL)    
            {
                answer = 1;
            }
            
        }
       
        //Waits for the asnwer with time out
    }while((answer == 0) && ((millis() - previous) < timeout));    

    return answer;
}

int8_t convert2Degrees(char* input){

    float deg;
    float minutes;
    boolean neg = false;    

    //auxiliar variable
    char aux[10];

    if (input[0] == '-')
    {
        neg = true;
        strcpy(aux, strtok(input+1, "."));

    }
    else
    {
        strcpy(aux, strtok(input, "."));
    }

    // convert string to integer and add it to final float variable
    deg = atof(aux);

    strcpy(aux, strtok(NULL, '\0'));
    minutes=atof(aux);
    minutes/=1000000;
    if (deg < 100)
    {
        minutes += deg;
        deg = 0;
    }
    else
    {
        minutes += int(deg) % 100;
        deg = int(deg) / 100;    
    }

    // add minutes to degrees 
    deg=deg+minutes/60;


    if (neg == true)
    {
        deg*=-1.0;
    }

    neg = false;

    if( deg < 0 ){
        neg = true;
        deg*=-1;
    }
    
    float numeroFloat=deg; 
    int parteEntera[10];
    int cifra; 
    long numero=(long)numeroFloat;  
    int size=0;
    
    while(1){
        size=size+1;
        cifra=numero%10;
        numero=numero/10;
        parteEntera[size-1]=cifra; 
        if (numero==0){
            break;
        }
    }
   
    int indice=0;
    if( neg ){
        indice++;
        input[0]='-';
    }
    for (int i=size-1; i >= 0; i--)
    {
        input[indice]=parteEntera[i]+'0'; 
        indice++;
    }

    input[indice]='.';
    indice++;

    numeroFloat=(numeroFloat-(int)numeroFloat);
    for (int i=1; i<=6 ; i++)
    {
        numeroFloat=numeroFloat*10;
        cifra= (long)numeroFloat;          
        numeroFloat=numeroFloat-cifra;
        input[indice]=char(cifra)+48;
        indice++;
    }
    input[indice]='\0';


}

Wrong geode?

no it’s work but the location far by few km from the right location , i think the wrong in the conversion of gps values
look here

int8_t convert2Degrees(char* input){

    float deg;
    float minutes;
    boolean neg = false;    

    //auxiliar variable
    char aux[10];

    if (input[0] == '-')
    {
        neg = true;
        strcpy(aux, strtok(input+1, "."));

    }
    else
    {
        strcpy(aux, strtok(input, "."));
    }

    // convert string to integer and add it to final float variable
    deg = atof(aux);

    strcpy(aux, strtok(NULL, '\0'));
    minutes=atof(aux);
    minutes/=1000000;
    if (deg < 100)
    {
        minutes += deg;
        deg = 0;
    }
    else
    {
        minutes += int(deg) % 100;
        deg = int(deg) / 100;    
    }

    // add minutes to degrees 
    deg=deg+minutes/60;


    if (neg == true)
    {
        deg*=-1.0;
    }

    neg = false;

    if( deg < 0 ){
        neg = true;
        deg*=-1;
    }
    
    float numeroFloat=deg; 
    int parteEntera[10];
    int cifra; 
    long numero=(long)numeroFloat;  
    int size=0;
    
    while(1){
        size=size+1;
        cifra=numero%10;
        numero=numero/10;
        parteEntera[size-1]=cifra; 
        if (numero==0){
            break;
        }
    }
   
    int indice=0;
    if( neg ){
        indice++;
        input[0]='-';
    }
    for (int i=size-1; i >= 0; i--)
    {
        input[indice]=parteEntera[i]+'0'; 
        indice++;
    }

    input[indice]='.';
    indice++;

    numeroFloat=(numeroFloat-(int)numeroFloat);
    for (int i=1; i<=6 ; i++)
    {
        numeroFloat=numeroFloat*10;
        cifra= (long)numeroFloat;          
        numeroFloat=numeroFloat-cifra;
        input[indice]=char(cifra)+48;
        indice++;
    }
    input[indice]='\0';


}

Are you saying that the positions from the raw NMEA sentences are accurate, but your interpretation is wrong?

AWOL:
Are you saying that the positions from the raw NMEA sentences are accurate, but your interpretation is wrong?

i think that,any help,please?

AWOL: Are you saying that the positions from the raw NMEA sentences are accurate, but your interpretation is wrong?

i forgot how to calculate the "Second" NMEA Degree,Minutes And seconds

any solution?

You could Google "degrees minutes seconds".

i knew that, but i couldn't add it to my code. :(

Post some example data so we can see. I have a pretty good idea what it is but I'd like to make sure first! :D

Latitude is 29.966667 longitude is 31.233333 but that's not my right location , my right location far away by 5KM At least i thought. :/

I've put those numbers into Google and they put it here:

https://www.google.com/maps/@29.966667,31.233333,16z ?

yes i did , and that's not my right location.

Can you provide the raw data? The full $GP... sentences?

dannable: Can you provide the raw data? The full $GP... sentences?

before converting?

Yes, before. Let's at least find out if the numbers are right to start with? $GPGGA can tell us quite a lot.

dannable: Yes, before. Let's at least find out if the numbers are right to start with? $GPGGA can tell us quite a lot.

Latitude: 2958.477281 Longitude: 3114.728315

Can you provide the raw data? The full $GP... sentences?

There is other data I'd like to see. I gather from your other thread that you think reception may be a problem?

dannable: There is other data I'd like to see. I gather from your other thread that you think reception may be a problem?

i don't understand :/

The raw data as it comes from the SIM908? For example:

$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,*47