is there any way to store fix.latitude() to a variable and fix.longitude() to variable?
Yes, you could store the two pieces in two separate variables. It would be better to store it in a structure of type Location_t
:
NeoGPS::Location_t someLocation;
...
void loop()
{
...
someLocation = fix.location;
}
You can access the pieces of that structure to get lat and lon:
Serial.print( someLocation.latF(), 6 );
Serial.print( ',' );
Serial.print( someLocation.lonF(), 6 );
Using a Location_t
structure will also let you use the distance and bearing calculation functions:
float distance = someLocation.DistanceKm( fix.location );
If you also want to store other GPS fields, you can declare another gps_fix
variable:
gps_fix snapshot;
void loop()
{
...
if (saveCurrent) {
snapshot = fix; // saves everything: lat,lon,alt,speed,heading,...
}
if (checkRange) {
float distance = snapshot.location.DistanceKm( fix.location );
if (distance > MAX_RANGE)
Serial.println( "too far!" );
it gives me 0.00 and 0.00 outputs.
Post your code in code tags: [code]--> your sketch in here --< [/code]
so it looks
like this.
I suspect that you are trying to use fix location before your GPS knows the location.
One thing I left out of the code above was checking for location validity:
// Display the current location
if (fix.location.valid) {
Serial.print( fix.latitude(), 6 );
Serial.print( ',' );
Serial.println( fix.longitude(), 6 );
} else {
Serial.println( '?' );
}
Did you run the first example program, NMEA.ino? (Described here.) You will have to make GPSport.h match what your sketch is using.
NMEA.ino will output all the fields it is receiving from the GPS device:
Status,UTC Date/Time,Lat,Lon,Hdg,Spd,Alt,Sats,Rx ok,Rx err,Rx chars,
3,2016-05-24 01:21:29.00,472852332,85652650,,138,,,1,0,66,
3,2016-05-24 01:21:30.00,472852311,85652653,,220,24040,7,9,0,557,
3,2016-05-24 01:21:31.00,472852315,85652647,,449,24080,7,17,0,1048,
If you don't see lat/lon values in each line, you do not have good satellite reception. Move closer to a window or go outside. The first fix could take 15 minutes or more.
Notice that the first field on each line is a "status". It should start at 0 and eventually get to 3 when it has a location fix. If the status stays at 0, the GPS device is not receiving a clear satellite signal.
Also notice the "Sats" field. That will tell you how many satellites it can "see". In the above example, it can see 7 satellites. The GPS device cannot provide a location until it sees at least 3 satellites.
Cheers,
/dev