[SOLVED] Latitude/Longitude

Quick question: I want to pass on GPS data as one single variable, and then using the Auto-location option to have it live-update on the map.

However, what format is recommended for this? Would a format such as 49.5473, -126.4312 (while named ‘gps’) be okay? Does it also matter which data-type is used for this?

Hardware is the Particle Electron 3G. Current way of sending data is as follow:
{“lat”: “%.04f”, “lon”: “%.04f”} , creating two seperate variables

Yes,

You should be send that data in the context field here and example https://github.com/ubidots/ubidots-particle/blob/master/examples/UbidotsSendValuesWithContext/UbidotsSendValuesWithContext.cpp

For more information about the position you can follow this article:

http://help.ubidots.com/user-guides/change-default-device-location

Gustavo.

1 Like

Thanks, works great!

However I noticed this:

sprintf(context, “lat=1.2343$lng=132.1233”);

However, instead of a pre-defined number I would like to put my own lat/lng variables in here. how should I pass that on?

Greetings,

the sprintf() is a special C function to create char arrays, simply store your latitude and longitude inside two variables and add it to the char array. You can reference to the usage of sprintf() here.

All the best

I tried this:

    float value1 = analogRead(A0);
    char context[25];
    sprintf(context, "%.2f, %.2f", lat, lng); //Sends latitude and longitude for watching position in a map
    Serial.println(context);
    ubidots.add("gps", value1, context);  // Change for your variable name
    ubidots.sendAll();
    delay(5000);

The serial prints 49.19, -123.10 but the Ubidots variable is no longer updated anymore. When I do sprintf(context, “%.2f %.2f”, lat, lng) (note the lack of comma) the data sends, but doesn’t update the location on the Dashboard.

1 Like

Nevermind, I think I solved it. If anyone reading this wonders how, this code should do the trick:

float value1 = analogRead(A0);
char context[25];
sprintf(context, "lat=%.2f$lng=%.2f", lat, lng); //Sends latitude and longitude for watching position in a map
Serial.println(context);
ubidots.add("gps", value1, context);  // Change for your variable name
ubidots.sendAll();
delay(5000);
3 Likes

Thanks for your feedback, much appreciate it!

All the best