Hello,
I am trying to put a location widget from my Particle code. I put instead of value=1 the accuracy of my location as a float. The converted sprintf function however, does not show up the location of my device and both the lng and lat values seem to be zero. I am not at that location My code is attached below, what would you suggest to be done in order to resolve this problem?
Hope to hear from someone soon,
Kerem
#include <Ubidots.h>
#ifndef TOKEN
#define TOKEN "token" // Put here your Ubidots TOKEN
#endif
#include <google-maps-device-locator.h>
Ubidots ubidots(TOKEN);
GoogleMapsDeviceLocator locator;
void setup() {
Serial.begin(9600);
// Scan for visible networks and publish to the cloud every 30 seconds
// Pass the returned location to be handled by the locationCallback() method
locator.withSubscribe(locationCallback).withLocatePeriodic(30);
}
void locationCallback(float lat, float lon, float accuracy) {
float lng=lon;
char context[25];
sprintf(context, "lat=%8.4f lng=%8.4f"); //Sends latitude and longitude for watching position in a map
ubidots.add("position",accuracy,context); // Change for your variable name
bool bufferSent = false;
if(ubidots.isDirty()){ // There are stored values in buffer
bufferSent = ubidots.sendAll();
}
if(bufferSent){
// Do something if values were sent properly
Serial.println("Values sent by the device");
}
}
void loop() {
locator.loop();
}
void locationCallback(float lat, float lon, float accuracy) {
float lng=lon;
char context[50];
sprintf(context, "lat=%f",lat,"lng=%f", lng); //Sends latitude and longitude for watching position in a map
ubidots.add("position",accuracy,context); // Change for your variable name
bool bufferSent = false;
if(ubidots.isDirty()){ // There are stored values in buffer
bufferSent = ubidots.sendAll();
}
if(bufferSent){
// Do something if values were sent properly
Serial.println("Values sent by the device");
}
}
With this edit, I managed to get the location in the context, and the correct location is visible in the ubidots system too, but I still cannot make it show up on the map. What is the problem in here?
2018-07-30 08:36:04 -04:00 1.00 lat:41.106052
2018-07-30 08:35:34 -04:00 1.00 lat:41.106010
2018-07-30 08:34:47 -04:00 1.00 lat:41.106030
2018-07-30 07:57:00 -04:00 1.00 lat:41.106026
2018-07-30 07:56:23 -04:00 1.00 lat:41.11
2018-07-30 07:55:53 -04:00 1.00 lat:41.11
This is a sample to show how my data is showing up. I tried rounding to get lng values but it did not work