I’m trying to get the Google Maps Device Locator working…
- I setup the Google API account and enabled the geolocation API
- I created the Google Maps integration in the Particle Console
- When I click the “test” it reports correctly (lat, long, accuracy) in the event log
I duplicated the sample code and modified it to this:
#include <google-maps-device-locator.h>
GoogleMapsDeviceLocator locator;
float glat;
float glon;
float gaccuracy;
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(15);
locator.withSubscribe(locationCallback).withLocatePeriodic(60);
}
void locationCallback(float lat, float lon, float accuracy) {
// Handle the returned location data for the device. This method is passed three arguments:
// - Latitude
// - Longitude
// - Accuracy of estimated location (in meters)
glat = lat;
glon = lon;
gaccuracy = accuracy;
}
void loop() {
//locator.publishLocation();
//delay (30000);
locator.loop();
char locate_data[128];
snprintf(locate_data, sizeof(locate_data), "{\"latitude\":\"%.15f\",\"longitude\":\"%.15f\",\"accuracy\":\"%.2f\"}", glat, glon, gaccuracy);
Particle.publish("locate_data", locate_data, PRIVATE);
delay(10000); // to ensure adhering to rate limit
}
But when I run it I consistently get 404 errors from the Google API…
Does anyone have any ideas? I have had this work, but it’s intermittent at best…
It also seems to take some time to respond to the request if it does work, or even if it errors… Is there a way to wait until a value is returned before publishing?
Thanks!
David