latitude and longitude

Hello, a question: how can I print latitude and longitude in serial, using the Arduino IDE?

Hey @Miguel,

And welcome to the Blues community! The easiest way to do this is with the Notecard’s card.location request.

Here’s a simple sketch that outputs the location in loop() every second.

#include <Arduino.h>
#include <Notecard.h>

#define usbSerial Serial

Notecard notecard;

void setup()
{
  // Wait for the serial port to become available for debugging
  static const size_t MAX_SERIAL_WAIT_MS = 5000;
  size_t begin_serial_wait_ms = ::millis();
  while (!usbSerial && (MAX_SERIAL_WAIT_MS > (::millis() - begin_serial_wait_ms)));
  usbSerial.begin(115200);
  notecard.setDebugOutputStream(usbSerial);

  notecard.begin();
}


void loop()
{
  J *req = notecard.newRequest("card.location");
  notecard.sendRequest(req);
  delay(1000);
}

TJ

Hi TJ!
Thank you so much!!
I appreciate the contribution friend!
One last question, I need to save latitude and longitude in two variables, how could I do that?

No problem :slight_smile: And try this:

// double or float—depends on how much precision you want
double lat;
double lon;
J *req = NoteNewRequest("card.location");
if (J *rsp = notecard.requestAndResponse(req))
{
  lat = JGetNumber(rsp, "lat");
  lon = JGetNumber(rsp, "lon");
  notecard.deleteResponse(rsp);
}

TJ

1 Like

Thanks bro! :+1:
You’re so cool!!!

1 Like