static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
What does this mean?
https://github.com/mikalhart/TinyGPSPlus/blob/master/examples/FullExample/FullExample.ino
The above link contains the full example program of that line.
This line is from tinygps++ library for extracting the coordinates and displaying in a table format. I'm using arduino uno, GSM module and GPS module to extract the coordinates and transmit it as message. Can anyone explain what dies this constant value mean and why do we use this?
-
5Unlike in movies, I hardly think London will ever move.Kwasmich– Kwasmich09/21/2020 08:21:40Commented Sep 21, 2020 at 8:21
-
1We declare those because the program in which they are declared wants to use that information in some way. Without knowing what the program is we can't say why it might want to know that information. Maybe it wants to work out how far from London you are.Majenko– Majenko09/21/2020 08:45:41Commented Sep 21, 2020 at 8:45
-
1This link contains the full program. Sorry to attach the link, since the program to too lengthy.tharrun kumar– tharrun kumar09/21/2020 08:50:48Commented Sep 21, 2020 at 8:50
-
1I'm currently working on a project, where the my location coordinates is to be sended as message using GSM module. The GPS coordinates are extracted using gps module. These are connected to arduino uno board. Tinygps and tinygps++ library is being used for this project. This program is an full example program which is default in tinygps++ librarytharrun kumar– tharrun kumar09/21/2020 08:53:45Commented Sep 21, 2020 at 8:53
-
1I was actually asking for a particular line, which was mentioned 1st. static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;tharrun kumar– tharrun kumar09/21/2020 12:15:02Commented Sep 21, 2020 at 12:15
2 Answers 2
Static variables are allocated storage only once in a program lifetime
The const keyword specifies that a variable's value is constant and tells the compiler to prevent the programmer from modifying it and you can't change const variable's value
and i guess you know double is a data type that can save floating point numbers
that line declare two variables with names LONDON_LAT
and LONDON_LON
and both of them are in one line
and because london's latitiude and longtitude doesn't change the const
keyword is used
also i guess because those variables are constants you can use #define
visit https://www.arduino.cc/reference/en/language/structure/further-syntax/define/
It's a good idea to declare variables the strictest possible way. So if you don't intend to change the value of LONDON_LAT at runtime, declare it as const.
This allows the compiler to alert you if your code tries to modify it, and it often allows the compiler to optimize the code.