Google Maps Device Locator Data Consumption on Electron

I’m using the google maps device locator library on my particle electron. Does anyone have information on the data consumption whenever it gets location data?

@lunchboxp How have you set up the location try? Once, Manual?

	switch(state)
	{
	case CONNECT_WAIT_STATE:
		if (Particle.connected())
		{
			state = CONNECTED_WAIT_STATE;
			stateTime = millis();
		}
		break;
	case CONNECTED_WAIT_STATE:
		if (millis() - stateTime >= waitAfterConnect)
		{
			// Wait several seconds after connecting before doing the location
			if (locatorMode == LOCATOR_MODE_ONCE)
			{
				publishLocation();

				state = IDLE_STATE;
			}
			else
			if (locatorMode == LOCATOR_MODE_MANUAL)
			{
				state = IDLE_STATE;
			}
			else
			{
				state = CONNECTED_STATE;
				stateTime = millis() - periodMs;
			}
		}
		break;
	case CONNECTED_STATE:
		if (Particle.connected())
		{
			if (millis() - stateTime >= periodMs)
			{
				stateTime = millis();
				publishLocation();
			}
		}
		else
		{
			// We have disconnected, rec
			state = CONNECT_WAIT_STATE;
		}
		break;
	case IDLE_STATE:
		// Just hang out here forever (entered only on LOCATOR_MODE_ONCE)
		break;
	}

The loop() call logic (for a photon) is as above. The device sets up a subscribe and then waits for connection to the cloud plus waitAfterConnect (10 seconds) - the subscribe handler then receives the lat, lon and accuracy. On wifi the deviceLocate message is 215 characters, I would guess the reply to be around 34 characters [3 floats with 6 decimal places as strings].

I used the following line of code in my loop:

   locator.withSubscribe(locationCallback).publishLocation();

So if I call this function, is there a danger of the code getting stuck in the idle state and for my code to just stop running?

That will publish the location only once. You need to use either withLocatePeriodic(secs) to do it every so many seconds, or include logic in your code to cll publishLocation() when you want to publish your location.

Also, it’s best to use withLocateOnce() instead of publishLocation() when chained off the subscribe like that because with SYSTEM_THREAD(ENABLED) that point is too early to successfully publish.

I put the publishLocation() inside my loop, so it publishes the location each time I go through the loop iteration. So what do you mean it will publish location only once?

Is the danger that I might call publishLocation() when there isn’t a cellular connection?

And yes I am using SYSTEM_THREAD(ENABLED). So would I call locator.withSubscribe(locationCallback).withLocationOnce() in the setup, and put locator.loop() inside my loop function code wherever I want the location to be published? In the tutorial (https://docs.particle.io/tutorials/integrations/google-maps/#run-the-google-maps-firmware-library-on-your-devices ) it says withLocationOnce() will only cause the location to be published one time when the device is first started up.

Edit: also what is cll?

This should go in setup and only be called once:

locator.withSubscribe(locationCallback);

In your loop, you can continue to use locator.publishLocation() but surround it with a test for Particle.connected() so you only do it when connected.

Also, make sure you rate limit the calls, you can only publish once per second.

1 Like