How to display the last gps position for a device stored in the database

Hi all ! :slight_smile:

I hope you are well,

I’m currently stuck on a data display issue on the map. Every day, I make 2 API calls which retrieve the latest information for each device, However I would only like to display the last position for a device, my problem currently is that all devices are displayed on the map.

I would like it to show me only 2 markers with the last position stored in the base. I tried with “Filter”, “Group By” but nothing conclusive. Is the data structure to change?

Thanks in Advance,


Are you using a map element from Bubble? If so, then to display just one marker you have to select a “Single” instead of "List, under the number of markers.

Hope this helps.

This I believe is supposed to be tracking the pieces of equipment. You have two pieces of equipment getting tracked here. You need to filter by created date.

You have to treat a date as a number, because that is what it is, a number of milliseconds…so you can filter using dates with greater than or less than etc.

You should also be able to sort by created date and use the descending to get them in the order of newest to oldest

Then you should be able to figure a way to filter out the same pieces of equipment so you only show the individual piece of equipment once.

Or if you don’t need to display where the equipment was previously and only need the most recent location and you don’t need to store previous locations in the database and only need to save a single location for each piece of equipment, which is the most current location of each piece of equipment, then you should not save each location as a new data entry and instead create you list of equipment and then change the location data field for each equipment that it has it’s location changed…so instead of having equipment 1 listed twice in two different locations on two different days, equipment 1 is listed only once and you only have the most recent location with the most recent date shown in the ‘modified date’ data field.

hi @boston85719,

thanks for your reply,

I need to know the location of an equipment with its movement history, what I am looking for is how to filter by equipment id?
since there are several, I only want the most recent.

same result with :

Hi @oleksiy,

I need to display a list of equipment by equipment id, knowing that in the database I can have several lines with the same id but not the same gps position, what I need to display is the most recent location by equipment id.
I hope it’s clear :wink:

That was to be expected, hence my comment above.

Filter that result…maybe use a :group by

Hi !

Unfortunately, on a map “group by” is not an option.

Im trying the option, i add a field name “Last Location” (yes/no) in database, but all new entries is yes, and the problem is how to change the old entries, i can’t find the good option.

I wouldn’t just give up on the :group by — create it as I described, but in a repeating group where it is possible…then see if you can use that repeating group as the datasource for the map — should be possible

I tried the option like this :

Including group by in the repeating group or in a map, for both options it doesn’t work. i simply want to display the last location per equipment.

Thanks a lot.

Ok, yeah, because the :group by function creates not a thing that is in the database, but rather a group so you should change the type of markers from grouping and make it the datatype you are trying to display…then when the datasource is red because your type is not a grouping, you have to select from the red datasource a thing that is part of the group

Would you mind taking a look, i share my app, :

I fixed it…your database was not set up in such a way to do what you were really wanting to do so I set up your database to enable it.

I created a datatype “Equipment Items”—this is just a list of your pieces of equipment, so each piece of equipment is listed only once…you can later add other data fields, but for now I just put ID…I’d suspect you’d want to add things like weight, owner etc. etc.

I created a datatype “Equipment-Histories” and have a data field that is of type “Equipment Items” to relate the two…also has a data field for address…each piece of equipment and each location they ever are located in will be listed here…it is basically the data type you created called ‘equipment’

I created a datatype “Equipment-Most-Recent-Location” it has a data field of type “Equipment Items” to relate the two data types…it also has a data field of address…this is the data type that you now have your map set to get the address of to set your markers.

Now all you need to do is set up your workflows for when a location of a piece of equipment is updated you make changes to thing ( the thing is “Equipment-Most-Recent-Location”) and you will also create a new thing ( the thing is “Equipment-Histories” ) and then you will be all set (mostly)

1 Like

Change the settings to make your app private again and maybe even delete that post you put the link in.

Thanks a lot @boston85719,

i tried to create a new entry for the equipment id 1 with a different address and unfortunately nothing happen in database and a map.

I don’t know what you would have done to try to do that, but if it was done correctly it should have updated the ‘equipment-most-recent-address’, which would have automatically updated your map

I simply added an entry by hand in the “Equipment Histories” database, with Id 1 and “Perpignan” (new city) as the address, I thought that the “Equipment Most Recent Location” database was starting automatically updated.

No it is not automatic

I want to simulate a new creation of an equipment when loading the page, in the workflow, so I create a new thing in the “Equipment-History” database, but problem, I cannot write the Id because it depends on the “Equipment Item” database, it’s a bit confusing for me, I shared the application again, can you give me an example of a workflow. thank you

Some of these concepts may be a bit more advanced. I would suggest doing some of the lessons provided by bubble to learn more about how data is edited, manipulated, created etc.

Hi @boston85719,

i was able to make some progress, base on your advice, however, i’m stuck on the last workflow to make a change to the “Most-Recent-Location” database, without a being able to change different entries. For the first and last item it’s working but for the other it doesn’t.

Thanks :slight_smile: