# Google Maps Device Locator Data Consumption on Electron

**URL:** <https://community.particle.io/t/google-maps-device-locator-data-consumption-on-electron/47192>\
**Category:** Cloud\
**Created:** [January 22, 2019, 5:10pm UTC](https://community.particle.io/t/google-maps-device-locator-data-consumption-on-electron/47192 "2019-01-22T17:10:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lunchboxp](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@lunchboxp](https://community.particle.io/u/lunchboxp)\
**Post date:** [January 22, 2019, 5:10pm UTC](https://community.particle.io/t/google-maps-device-locator-data-consumption-on-electron/47192/1 "2019-01-22T17:10:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![armor](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/armor/32/18398_2.png) [@armor](https://community.particle.io/u/armor)\
**Post date:** [January 24, 2019, 10:47am UTC](https://community.particle.io/t/google-maps-device-locator-data-consumption-on-electron/47192/2 "2019-01-24T10:47:01Z")

</div>

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

```auto
	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].

---

<div class="post-metadata">

**Author:** ![lunchboxp](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@lunchboxp](https://community.particle.io/u/lunchboxp)\
**Post date:** [January 24, 2019, 6:18pm UTC](https://community.particle.io/t/google-maps-device-locator-data-consumption-on-electron/47192/3 "2019-01-24T18:18:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [January 24, 2019, 6:22pm UTC](https://community.particle.io/t/google-maps-device-locator-data-consumption-on-electron/47192/4 "2019-01-24T18:22:24Z")

</div>

> [@lunchboxp](#):
>
> locator.withSubscribe(locationCallback).publishLocation();

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.

---

<div class="post-metadata">

**Author:** ![lunchboxp](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@lunchboxp](https://community.particle.io/u/lunchboxp)\
**Post date:** [January 24, 2019, 7:02pm UTC](https://community.particle.io/t/google-maps-device-locator-data-consumption-on-electron/47192/5 "2019-01-24T19:02:19Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [January 24, 2019, 7:15pm UTC](https://community.particle.io/t/google-maps-device-locator-data-consumption-on-electron/47192/6 "2019-01-24T19:15:12Z")

</div>

This should go in setup and only be called once:

```auto
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.
