Odd Map Widget Behavior

Hello,
I’ve been having tons of fun with Blynk lately. Thank you.
I’m using latest Blynk on Android with AssetTracker shield and Electron.
For some reason somewhere along my travel path a marker will remain at some random location. This will cause the map to remain focused on that position while the updated marker moves off the map. Hitting the lens again will scale the map to show both markers. I only want one marker. I have no idea why a second is created.

Here is my complete code. Sorry about the crappy formatting.

#include <blynk.h>
#include <google-maps-device-locator.h>
#include <AssetTracker.h>
#include <time.h>
#include <string.h>
#define BLYNK_PRINT Serial // Defines the object that is used for printing
#define BLYNK_DEBUG        // Optional, this enables more detailed prints

SYSTEM_MODE(AUTOMATIC);

char auth[] = "EAT AT JOE's";
String symbol[] = {"/","—","\\","|"};
unsigned int pos = 0;
unsigned gpsLoop;
AssetTracker t = AssetTracker();
BlynkTimer Timer;
FuelGauge fuel;
WidgetLCD lcd(V4);
WidgetMap myMap(V0);
GoogleMapsDeviceLocator locator;

void setup() {
   Serial.begin(9600);
   Blynk.begin(auth); 
   t.begin();
   t.gpsOn();
  locator.withSubscribe(locationCallback).withLocateOnce();
  gpsLoop = Timer.setInterval(15000L, myGPSUpdate);
  Timer.enable(gpsLoop);
  Time.zone(-8);
  }

void loop() {
    t.updateGPS();
    Blynk.run();  
    Timer.run();
   }

//update position
void myGPSUpdate(){
    if(t.gpsFix()){
          String LatLon1 = t.readLatLon();
          float Lat1 = t.readLatDeg();
          float Lon1 = t.readLonDeg();
          unsigned int index = 1;
          myMap.location(index, Lat1, Lon1, Time.format(Time.now(), "%I:%M%" ));
          lcd.print(0,1, "Last GPS " + Time.format(Time.now(), "%I:%M%" ) + " " + symbol[pos]);
           pos++;
           if (pos >= 4){
               pos = 0;
           }
          
       } else {locator.loop();}
}
//get battery health and write to LCD
BLYNK_WRITE(V2){
   if ( param.asInt() ){
    float lastBatt = fuel.getSoC();
    float lastV = fuel.getVCell();
    lcd.print(0,0, "Batt:" + String::format("%.2f", lastV) + "V " + String::format("%.1f",lastBatt) + "%");
   }  
}
//use slider to change reporting frequency from 300s to 5s to save data, default is 15s
BLYNK_WRITE(V1){
    //String newtime = String::format("%u", param.asInt() ) + "L";
    unsigned int val = param.asInt();
    Timer.disable(gpsLoop);
    gpsLoop = Timer.setInterval(val*1000L, myGPSUpdate);
     Timer.enable(gpsLoop);
     lcd.print(0,0, "Period: " + String::format("%u",val) + "s    " );
}

//listen for GSM positions by Google API and update location 
void locationCallback(float lat, float lon, float accuracy) {
   int index = 1;
   myMap.location(index, lat, lon, Time.format(Time.now(), "%I:%M%" ) );
   lcd.print(0,1, "Cell Location " + symbol[pos] );
   pos++;
   if (pos >= 4){
   pos = 0;
   }
}

I don’t know why you get the extra marker, but you can just try clearing the map each time before placing the next one.

myMap.clear();

I’m sure that’s a waste of bandwidth, but I can’t think of anything better. I’ll take it as an interim solution. Thanks for the help.

Drop in the bucket :wink:

@BlynkAndroidDev - we had this issue before. Could you please check?
@Slide - thanks for sharing the code. I will re-use it in my project.

They need to do a better API for this location callback or maybe it’s just too difficult for me :slight_smile:

@Slide @Pavel - quick fix for your issue would be a change of all ‘index = 1’ to ‘index = 0’, as indexes are starting from 0, not from 1.

1 Like

Yes! I just forgot it.
BTW, how difficult is it to add tracking lines rendering?