Asset Tracker GPS real-time google map

I created a simple browser based app to show the location of your Electron Asset Tracker Shield on a Google map in realtime.

Source code is at

Or you can just use it by logging in with your Particle credentials here: and choosing your Electron.


What GPS unit did you use for this please?

So was the Electron sitting exactly where the Pin is showing or was it in one of those cars?

Thanks for offering the code to do this outside of some other platform. also allows you to setup this same live google map tracking with also logging the path of travel.

@BrianMoreau I used the Asset Tracker Shield that I got with my Electron Kickstarter reward.


@RWB The electron was about 5 feet from where that map marker is.


I got the website part working but I cannot seem to get the spark to publish the coordinates. Would you have a dump of your spark?

Hi Hypnopompia,

It looks good.
I’m not suggesting anything untoward but I was a little wary (given all the internet scams etc) of the login box.
I was just wondering if there’s any way for a developer like yourself of proving to users that what appears to be a Particle Login box at your link below is legitimate? i.e. that it is directly to the particle cloud and you do not get access to users account names and passwords?


Well you can run it on your own server/laptop using the open source code shared :wink:

That’s a great observation @wwy. The login box that shows up on that page is provided by the official sparkjs library. That library is doing all the heavy lifting of displaying the login box and using the credentials to obtain an access token. However, I do see security risks with that method as well. It would be easy for a rogue site to tap into those fields and steal a password.

I would really like to see an oauth login process for stuff like this that would allow 3rd parties to obtain a token on the user’s behalf from particle. It would also be nice to let the user specify which devices the token has access to during the oauth process. Then I don’t have to give a 3rd party access to all my particle devices. I think I’ll raise this issue with the particle team and see what they think. @Dave, what do you think?

But yes, in the mean time if you’re worried about it (I wouldn’t blame you) I suggest hosting the page on your own server and reviewing the code.

1 Like

@Domasi The firmware I’m using is the example from the official particle library for the asset tracker:

If you’ve got that loaded and your electron still isn’t publishing gps coordinates, it’s probably because your GPS doesn’t have a fix on the satellites. Make sure the device is outside with a clear line of sight to the sky. I noticed I had issues the other night when it was really cloudy. I ordered an external antenna as well. It can also take a long time for it to get a GPS fix. In some cases, it’s taken 20 minutes for me. I’m hoping the antenna resolves this. You can also get battery for the asset tracker shield that is supposed to help with warm-up times on getting a gps fix. I haven’t seen much improvement from that solution yet.

1 Like


Thanks for the info. I have had mine out there for 45 minutes with no updates. I am new to this and want to make sure I am doing it right. Once I get a working example I can figure it out…

Try resetting it and see if that helps.

I have used the same GPS receiver before and it took a fair amount of time to get the first fix. Take it outside and make sure there are no obstructions from a clear view of the sky for quickest GPS lock.

Also be sure to put that coin cell battery in there since it does help all future GPS locks if your in the same area before you turn the unit off.

I can get a GPS fix inside my garage in just a few mins from a cold start with the coin cell battery installed.

I use it to track the position of the sun.

Done that and reflashed it.

This is what I have in the spark along with the assettracker library… it is a carbon copy with the exception that I am updating every minute vs 10

/* -----------------------------------------------------------
This example shows a lot of different features. As configured here
it'll check for a good GPS fix every 10 minutes and publish that data
if there is one. If not, it'll save you data by staying quiet. It also
registers 3 Particle.functions for changing whether it publishes,
reading the battery level, and manually requesting a GPS reading.

// Getting the library
#include "AssetTracker/AssetTracker.h"

// Set whether you want the device to publish data to the internet by default here.
// 1 will Particle.publish AND Serial.print, 0 will just Serial.print
// Extremely useful for saving data while developing close enough to have a cable plugged in.
// You can also change this remotely using the Particle.function "tmode" defined in setup()
int transmittingData = 1;

// Used to keep track of the last time we published data
long lastPublish = 0;

// How many minutes between publishes? 10+ recommended for long-time continuous publishing!
int delayMinutes = 1;

// Creating an AssetTracker named 't' for us to reference
AssetTracker t = AssetTracker();

// A FuelGauge named 'fuel' for checking on the battery state
FuelGauge fuel;

// setup() and loop() are both required. setup() runs once when the device starts
// and is used for registering functions and variables and initializing things
void setup() {
    // Sets up all the necessary AssetTracker bits
    // Enable the GPS module. Defaults to off to save power. 
    // Takes 1.5s or so because of delays.
    // Opens up a Serial port so you can listen over USB
    // These three functions are useful for remote diagnostics. Read more below.
    Particle.function("tmode", transmitMode);
    Particle.function("batt", batteryStatus);
    Particle.function("gps", gpsPublish);

// loop() runs continuously
void loop() {
    // You'll need to run this every loop to capture the GPS output

    // if the current time - the last time we published is greater than your set delay...
    if(millis()-lastPublish > delayMinutes*60*1000){
        // Remember when we published
        lastPublish = millis();
        //String pubAccel = String::format("%d,%d,%d",t.readX(),t.readY(),t.readZ());
        //Particle.publish("A", pubAccel, 60, PRIVATE);
        // Dumps the full NMEA sentence to serial in case you're curious
        // GPS requires a "fix" on the satellites to give good data,
        // so we should only publish data if there's a fix
            // Only publish if we're in transmittingData mode 1;
                // Short publish names save data!
                Particle.publish("G", t.readLatLon(), 60, PRIVATE);
            // but always report the data over serial for local development

// Allows you to remotely change whether a device is publishing to the cloud
// or is only reporting data over Serial. Saves data when using only Serial!
// Change the default at the top of the code.
int transmitMode(String command){
    transmittingData = atoi(command);
    return 1;

// Actively ask for a GPS reading if you're impatient. Only publishes if there's
// a GPS fix, otherwise returns '0'
int gpsPublish(String command){
        Particle.publish("G", t.readLatLon(), 60, PRIVATE);
        // uncomment next line if you want a manual publish to reset delay counter
        // lastPublish = millis();
        return 1;
    else { return 0; }

// Lets you remotely check the battery status by calling the function "batt"
// Triggers a publish with the info (so subscribe or watch the dashboard)
// and also returns a '1' if there's >10% battery left and a '0' if below
int batteryStatus(String command){
    // Publish the battery voltage and percentage of battery remaining
    // if you want to be really efficient, just report one of these
    // the String::format("%f.2") part gives us a string to publish,
    // but with only 2 decimal points to save space
          "v:" + String::format("%.2f",fuel.getVCell()) + 
          ",c:" + String::format("%.2f",fuel.getSoC()),
          60, PRIVATE
    // if there's more than 10% of the battery left, then return 1
    if(fuel.getSoC()>10){ return 1;} 
    // if you're running out of battery, return 0
    else { return 0;}
1 Like

Do you see any events come through in your particle dashboard?


Try sending an event to your electron to get it to report the battery status. Let’s make sure everything else is working besides the GPS for now.

If you have the particle CLI installed, run this:

particle call Electron3G batt

and replace Electron3G with the name of your electron.

After that, should should see a “B” event in your dashboard with the voltage and % of battery. If that works, then everything else is good, but your GPS is just having a really bad day with getting a fix. You might try getting an external antenna.

Function call failed Function batt not found

Saying it has 0 functions.

Update: particle call batt now shows 1 and gps shows 0

ok. that’s good that you can call those functions now. calling the batt function should make an event appear in your dashboard. the gps function should as well as long as the function returns 1, which means it has a GPS fix. If that function call is returning 0, it means the gps isn’t getting a fix.

but you’re getting closer!