particle-iot / google-maps-device-locator

MIT License
24 stars 9 forks source link

Callback never triggered when using .withSubscribe(locationCallback) #1

Open armanafghani opened 7 years ago

armanafghani commented 7 years ago

I'm attempting to get an approximate geolocation of my Particle Electron using this library, but when I follow the example and add the .withSubscribe option to the locator, the callback is never called.

Here is the full code I'm running on my Electron:

#include "google-maps-device-locator.h"
SerialLogHandler logHandler;

GoogleMapsDeviceLocator locator;

void locationCallback(float lat, float lon, float accuracy)
{
  Serial.println(lat);
  Serial.println(lon);
  Serial.println(accuracy);
}

void setup() {
    Serial.begin(9600);
  locator.withSubscribe(locationCallback).withLocatePeriodic(120);
}

void loop() {
    locator.loop();
}

and the serial output I get from the serial monitor over a span of about 10 minutes is as follows:

publishLocation scanData={"c":{"o":"T-Mobile","a":[{"i":27126975,"l":32608,"c":310,"n":260}]}} publishLocation scanData={"c":{"o":"T-Mobile","a":[{"i":27126975,"l":32608,"c":310,"n":260}]}} publishLocation scanData={"c":{"o":"T-Mobile","a":[{"i":27126975,"l":32608,"c":310,"n":260}]}} publishLocation scanData={"c":{"o":"T-Mobile","a":[{"i":27126975,"l":32608,"c":310,"n":260}]}} publishLocation scanData={"c":{"o":"T-Mobile","a":[{"i":27126975,"l":32608,"c":310,"n":260}]}} publishLocation 0000612038 [app] INFO: unknown key=Ci value=690c 0000612038 [app] INFO: unknown key=Bsic value=34 scanData= publishLocation scanData={"c":{"o":"T-Mobile","a":[{"i":27126975,"l":32608,"c":310,"n":260}]}} publishLocation scanData={"c":{"o":"T-Mobile","a":[{"i":27126975,"l":32608,"c":310,"n":260}]}}

Am I doing something wrong? How should I interpret the two INFO lines?

Thanks for the help!

rickkas7 commented 7 years ago

The two INFO messages are not a problem. There are some extra keys that came back from the cellular modem, but we don't need those to do location so it's not harmful.

The actual problem appears to be that Google geolocation doesn't seem to know the location of your tower. You can tell if you open the Logs tab in the console. If you get back a hook-error/deviceLocator/0 with an error 404, the location is not known. I manually entered the tower above and it shows up as not known for me.

The response callback is not called when the location is not known, which is why it's not getting called.