Google Maps integration

Hello there again!
Have a question about the Positioning system in Boron LTE, Google Maps integration and in special GoogleMapsDeviceLocator. For short, it returns 0,0 and a response in Integration the following:

But when I Test integration from Particle Console it works well:

My code (for testing runs once in setup only):

// This #include statement was automatically added by the Particle IDE.
#include <google-maps-device-locator.h>

// This #include statement was automatically added by the Particle IDE.
#include <HttpClient.h>

GoogleMapsDeviceLocator locator;

HttpClient http;
const char* serverUrl = "3.69.177.92";
const int port = 3099;
const char* endpoint = "/api/v1/status";

const int pressureTransducerPin = A0;

const char* deviceName = "WP-O-Meter-1";
String status = "OFF";
double pressure;
float latitude;
float longitude;

http_request_t request;
http_response_t response;

http_header_t headers[] = {
    { "Content-Type", "application/json" },
    { "Accept" , "*/*"},
    { NULL, NULL }
};

void setup() {
    Serial.begin(9600);
    Network.on();
    Network.connect();
    
    pinMode(pressureTransducerPin, INPUT);
    
    locator.withSubscribe(locationCallback).withLocateOnce();
    locator.loop();
    status = getStatus();
    if (status == "ON") {
        pressure = getPressure();
        String location = getLocation(latitude, longitude);
        sendPostRequest(pressure, location, status);
    }
    Network.disconnect();
}

Question: what could be wrong with my actions in setting up positioning?

In the first case, the most likely reason is that the cellular tower is not known by Google. There is no central database of towers, and Google generates their list by Android devices that know both their actual location (from phone GPS) and cellular tower information, and don't opt out of providing that information. The database is not complete. You can tell because error 404 was returned, which is "not found."

I'm kind of surprised the Test button works because the request won't have a cell ID or Wi-Fi information. It's probably falling back to IP geolocation when there is no cell or Wi-Fi information. Note that the accuracy is 103,652 meters, or about 64 miles. I suspect that the lat, lng is not the location of your device.

1 Like

Exactly. The device is located in Canada, but the lat and lng retrieved by the Test button relate to the location in the USA. Are there other ways to get the location of the device? Because 0, 0 is not the result my customer is expecting from me :melting_face:
image

I didn't see an implementation for getLocation() so I can't be sure what it's doing, but I'm guessing that since the Google API returned 404 (not found) it's just returning the default values of lat and lng, which are 0 since no location was sent to the device because it's not known.

Short of there being a bug somewhere, there won't be a way to location this device by cell ID because it appears to not be known by the Google geolocation API.

1 Like

This method just converts received from locationCallback() latitude and longitude into String for sending as JSON to the server:

// This #include statement was automatically added by the Particle IDE.
#include <google-maps-device-locator.h>

// This #include statement was automatically added by the Particle IDE.
#include <HttpClient.h>

GoogleMapsDeviceLocator locator;

HttpClient http;
const char* serverUrl = "3.69.177.92";
const int port = 3099;
const char* endpoint = "/api/v1/status";

const int pressureTransducerPin = A0;

const char* deviceName = "WP-O-Meter-1";
String status = "OFF";
double pressure;
float latitude;
float longitude;

http_request_t request;
http_response_t response;

http_header_t headers[] = {
    { "Content-Type", "application/json" },
    { "Accept" , "*/*"},
    { NULL, NULL }
};

void setup() {
    Serial.begin(9600);
    Network.on();
    Network.connect();
    
    pinMode(pressureTransducerPin, INPUT);
    
    locator.withSubscribe(locationCallback).withLocateOnce();
    locator.loop();
    status = getStatus();
    if (status == "ON") {
        pressure = getPressure();
        String location = getLocation(latitude, longitude);
        sendPostRequest(pressure, location, status);
    }
    Network.disconnect();
}

void loop() {
    
}

void locationCallback(float lat, float lon, float accuracy) {
    latitude = lat;
    longitude = lon;
}
 
String getLocation(float lat, float lon) {
    String location = String(lat) + ", " + String(lon);
    return location;
}

There will be some delay (several seconds) between the time the location is requested at boot and the time that the location comes back. And it will only occur after you've connected to the cloud. You will probably need to add a flag in the location callback to indicate that the location has been received successfully.

That's not the bug because the Google API is returning a 404, but if it was returning a 200 OK you'd probably still get a 0,0 location because it wouldn't have been received by the device yet.

When I called locator.publishLocation() there is the following event in the Console:

Yes, those are the cell identifier, LAC, MCC, and MNC of your device. I manually entered them into the Google geolocation API and got a 404 as well, so Google doesn't know the location of that tower.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.