Basic coding help - GPS fence trigger for IOS


I’m new to coding so please forgive me if my questions are basic… :blush: My questions are related to this GPS Stream example, and are probably based around general handling of functions.

  1. I want to just get the int values of this section of code ‘’ Serial.println(gps.getLat(), 7); ‘’, but i can’t get this (“gps.getLat(), 7”) to work as a function to return a value?

  2. A general question with the examples such as the on in the link above - Why do I have to always use the code within a function called ‘‘BLYNK_WRITE(VX)’’ and not just write it into its own function in something like this:

timer.setInterval(6000L, GpsPosition); 

void GpsPosition(){
GpsParam gps(param);

  // Print 6 decimal places for Lat, Lon
  Serial.print("Lat: ");
  Serial.println(gps.getLat(), 7);

  Serial.print("Lon: ");
  Serial.println(gps.getLon(), 7);

  // Print 2 decimal places for Alt, Speed
  Serial.print("Altitute: ");
  Serial.println(gps.getAltitude(), 2);

  Serial.print("Speed: ");
  Serial.println(gps.getSpeed(), 2);


I know this is probably pretty basic, but i don’t seem to understand whats going on here. Once i can get the value of the lat’s and long’s into int values (or long int values for that matter) i will be able to set up my GPS fence as IOS doesnt have a GPS radius trigger.

thanks for your help!!

BLYNK_WRITE is a C macros that makes it possible to read incoming Values from the app in “kind of” a non-blocking manner

Lat and Long are not integers, they are floats

You need to declare global variables and assign values to them inside of the macros. Then you can use these variables everywhere in your sketch.

Hi Pavel,

thanks for getting back to me.


Yup, ok got it.

With regards to my first question:

I still can’t work out how to extract the value from the code. For example this doesn’t work as it only returns a value of -37.71

  GpsParam gps(param);
  float Lat;
  Lat = gps.getLat(),7;

if i use the example code from here and cut it down to this it gives the lat correctly (-37.7141340):

  GpsParam gps(param);
  // Print 6 decimal places for Lat, Lon

  Serial.println(gps.getLat(), 7);

Are you able to help me write the first bit to extract it to a value? Once i have this i will be able to build a GPS fence, which i can then share with everyone in the same situation.

Try this:

  GpsParam gps(param);
  float Lat;
  Lat = gps.getLat();

The “,7” part of the code is a formatting switch used as part of the Serial.print macro to give 7 decimal places.

Also, by using float Lat; you’re declaring Lat as a LOCAL variable, not GLOBAL, so you wont be able to use it outside of the BLYNK_WRITE(V5) function.


Pete - your a legend!

The missing piece of information for me was the “, 7”. I was able to make my own functions, but because it was only giving 2 decimal places i thought there was something wrong with how i wrote it but had no idea the serial print was decimal place limited! its working how i need it to now, thanks so much!

ill build an example GPS fence trigger for ppl and post it later.