"class has no member" error

My code is attached to this post.

My code:

#include <SoftwareSerial.h>
#include <BlynkSimpleSerialBLE.h>
#include <TinyGPS++.h>
#include <math.h>

#include "TinyGPS++.h" /* try to remove these 2 includes */
#include "SoftwareSerial.h"


#define TxD 8
#define RxD 9


SoftwareSerial serial_connection(0,1);
SoftwareSerial bluetoothSerial(TxD, RxD);
TinyGPSPlus gps;


float lat2 = gps.getLat();
float lat1 = gps.location.lat();
float lon2 = gps.getLon();
float lon1 = gps.location.lng();

double latR1;
double latR2;
double lonR1;
double lonR2;
double dlon;
double dlat;
double a;
double e;
double d;
double R = 6371.00;
double toDegrees = 57.295779;

char sb[10];
char auth[] = "b3a6efffe4424417b71b3184fc24c61b";


BLYNK_WRITE(V2) 
{
  GpsParam gps(param);
  Serial.println("Received remote GPS: ");
  Serial.print(gps.getLat(), 7); 
  Serial.print(", "); 
  Serial.println(gps.getLon(), 7);
}


void setup()
{
  Serial.begin(9600);
  bluetoothSerial.begin(9600);
  Blynk.begin(bluetoothSerial, auth);
  serial_connection.begin(9600);
  Serial.println("GPS Start");
}


void loop()
{
  Blynk.run();
  
  while(serial_connection.available())
  {
    Serial.println("There is connection to GPS!");
    gps.encode(serial_connection.read());
  }
  if(gps.location.isUpdated())
  {
    Serial.println("Satellite Count:");
    Serial.println(gps.satellites.value());
    Serial.println("Latitude:");
    Serial.println(gps.location.lat(), 6);
    Serial.println("Longitude:");
    Serial.println(gps.location.lng(), 6);
    Serial.println("Speed MPH:");
    Serial.println(gps.speed.mph());
    Serial.println("Altitude Feet:");
    Serial.println(gps.altitude.feet());
    Serial.println("");
  }
}


void calcDist()
{ 
  Serial.begin(9600);
  float delLat = abs(lat1-lat2)*111194.9;
  float delLong = 111194.9*abs(lon1-lon2)*cos(radians((lat1+lat2)/2));
  float distance = sqrt(pow(delLat,2)+pow(delLong,2));
  Serial.print("Distance to destination(KM): ");
  Serial.println(distance,7);

  lonR1 = lon1*(PI/180);
  lonR2 = lon2*(PI/180);
  latR1 = lat1*(PI/180);
  latR2 = lat2*(PI/180);
  
  dlon = lonR2 - lonR1;
  dlat = latR2 - latR1;

  double x = cos(latR2)*sin(lonR2-lonR1); 
  double y = cos(latR1)*sin(latR2)-sin(latR1)*cos(latR2)*cos(lonR2-lonR1);

  float brRad = atan2(x, y);
  float reqBear = toDegrees*brRad;
  
  Serial.print("Bearing(°): ");
  Serial.println(reqBear, 7);
}

The error that comes up is:

GPS_final2:19: error: 'class TinyGPSPlus' has no member named 'getLat'

float lat2 = gps.getLat();

^

GPS_final2:21: error: 'class TinyGPSPlus' has no member named 'getLon'

float lon2 = gps.getLon();

^

exit status 1
'class TinyGPSPlus' has no member named 'getLat'

So the library does not allow gps.getLat() and gps.getLon() which is from:

BLYNK_WRITE(V2) 
{
 GpsParam gps(param);
 Serial.println("Received remote GPS: ");
 Serial.print(gps.getLat(), 7); 
 Serial.print(", "); 
 Serial.println(gps.getLon(), 7);
}

So I want to somehow make gps.getLat() = lat2 and gps.getLon() =lon2
but I don't know how to.

I can ensure you that the rest of the code is error-free.
Any help would be very much appreciated.

GPS_final.ino (2.29 KB)

Welcome to the Forum. Please read this post:

How to use this forum - please read.

Please post your code using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpreted by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.

Unless the sketch is too large, it's better if you post your code, rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.

Does the example code that uses getLat() and getLon() use the same GPS library as your code ?

yes

Is this the library you're using?

Why are you trying to get lat / lng two different ways?

float lat2 = gps.getLat();
float lat1 = gps.location.lat();
float lon2 = gps.getLon();
float lon1 = gps.location.lng();

Take a look at the examples that come with the library. Only the longer form is valid.

Yes, that is the library I am using.

I am trying to get lat / lng not in two different ways but of two different points(Arduino and phone).

I know that only the longer form is valid.

Ultimately, I am trying to program a robot that can follow my phone using GPS Latitude and Longitude(but this code is not completed yet as I am yet to program the motors).

For this code, I am trying to get the GPS Latitude and Longitude of a phone using the Blynk software which helps to connect the phone to arduino. Then I am trying to get the GPS Latitude and Longitude of the Arduino using a GPS NEO 6M. After that I calculate the distance between the 2 GPS points and the degrees I need to make my robot turn(using the bearings value) and face in the direction of the phone.

VanillaUnicorn:
yes

Sure ?

I cant find getLat or getLon anywhere in the TinyGPSPlus library, code or examples.

There is a another library that uses getLat however.

@srnet No no thats not what I meant.

gps.getLat() and gps.getLon() is from BlynkSimpleSerialBLE.h

gps.location.lat() and gps.location.lng() is from TinyGPS++.h

I am trying to get GPS latitude and longitude of the arduino(with BlynkSimpleSerialBLE) and the phone(with TinyGPS++.h).

float lat2 = gps.getLat();
float lat1 = gps.location.lat();
float lon2 = gps.getLon();
float lon1 = gps.location.lng();

gps.getLat() and gps.getLon() can be seen in Documentation for Blynk, the most popular IoT platform for businesses.

Then you should use meaningful variable names so you don't have to guess... for example

float latArduino = gps.getLat();
float latPhone = gps.location.lat();
float lonArduino = gps.getLon();
float lonPhone = gps.location.lng();

First, it would be preferable to give your Blynk GpsParam and TinyGPSPlus objects different names rather than calling them both 'gps'. Second, the Blynk GpsParam object is only in-scope within this function:

BLYNK_WRITE(V2) 
{
  GpsParam gps(param);
  Serial.println("Received remote GPS: ");
  Serial.print(gps.getLat(), 7); 
  Serial.print(", "); 
  Serial.println(gps.getLon(), 7);
}

Rather than just printing the Lat / Lon values, save them to a global variable so they can be used elsewhere.

aarg:
Then you should use meaningful variable names so you don't have to guess... for example

float latArduino = gps.getLat();

float latPhone = gps.location.lat();
float lonArduino = gps.getLon();
float lonPhone = gps.location.lng();

Yes sure thing. I'll do that but the error is still there. Sorry if the code is not very organised.

VanillaUnicorn:
Yes sure thing. I'll do that but the error is still there.

Did you read Reply #9?

gfvalvo:
First, it would be preferable to give your Blynk GpsParam and TinyGPSPlus objects different names rather than calling them both 'gps'. Second, the Blynk GpsParam object is only in-scope within this function:

BLYNK_WRITE(V2) 

{
  GpsParam gps(param);
  Serial.println("Received remote GPS: ");
  Serial.print(gps.getLat(), 7);
  Serial.print(", ");
  Serial.println(gps.getLon(), 7);
}




Rather than just printing the Lat / Lon values, save them to a global variable so they can be used elsewhere.

If I want to change the name, would I have to change it from the library itself?
How do I make a global variable?

change

TinyGPSPlus gps;

to

TinyGPSPlus someothername;

aarg:
change

TinyGPSPlus gps;

to

TinyGPSPlus someothername;

Ok I did as told and I get the error:

GPS_final2:19: error: 'gps' was not declared in this scope

float lat2 = gps.getLat();

^

GPS_final2:21: error: 'gps' was not declared in this scope

float lon2 = gps.getLon();

^

exit status 1
'gps' was not declared in this scope

how can I solve this error?

VanillaUnicorn:
If I want to change the name, would I have to change it from the library itself?
How do I make a global variable?

I didn't say make the GpsParam object global. I said assign the Lat / Lon values that it provide to global variables.

VanillaUnicorn:
@srnet No no thats not what I meant.

But its what you wrote, which is all we can know.

When you do this;

TinyGPSPlus gps;

and

float lat2 = gps.getLat();
float lat1 = gps.location.lat();

The gps. function calls all get passed to the TinyGPSPlus library, which does not have a function called getLat().

You would not normally modify a Library such as TinyGPSPlus (which reads a GPS) to talk to another device say a remote connection via Bluetooth.

I use TinyGPSplus for my tracker, the local lat and long come from a remote device via a radio link, I then pass local and remote GPS co-ordinates to TinyGPSPlus to calculate the distance and direction between the two. Last thing I would need to do is modify the TinyGPSPlus standard Library.

gfvalvo:
I didn't say make the GpsParam object global. I said assign the Lat / Lon values that it provide to global variables.

How can I do that?

srnet:
But its what you wrote, which is all we can know.

When you do this;

TinyGPSPlus gps;

and

float lat2 = gps.getLat();
float lat1 = gps.location.lat();

The gps. function calls all get passed to the TinyGPSPlus library, which does not have a function called getLat().

You would not normally modify a Library such as TinyGPSPlus (which reads a GPS) to talk to another device say a remote connection via Bluetooth.

I use TinyGPSplus for my tracker, the local lat and long come from a remote device via a radio link, I then pass local and remote GPS co-ordinates to TinyGPSPlus to calculate the distance and direction between the two. Last thing I would need to do is modify the TinyGPSPlus standard Library.

Ok, so to avoid this I changed TinyGPSPlus gps to TinyGPSPlus arduino and all the involved gps codes accordingly. But after that, I get the error shown in Post#14.

VanillaUnicorn:
Ok, so to avoid this I changed TinyGPSPlus gps to TinyGPSPlus arduino and all the involved gps codes accordingly. But after that, I get the error shown in Post#14.

But you cant have removed all the gps. function calls, the compiler is saying you have not.

And tells you the ones you have not removed are on lines 19 and 21.