Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push custom value to Google Maps marker

I want to push a custom var to dynamically loaded Google Maps markers (with live user positions) {via javascript}. In this case, I want to push a UNIX timestamp into the marker, so that way I can keep track of marker timing. After a set interval, JS scans for markers timestamps that reach an expired time period -> then remove them.

I wanted to see if any one else played with this similar idea.

like image 338
MKN Web Solutions Avatar asked Jun 27 '26 07:06

MKN Web Solutions


1 Answers

The good thing about the Google Maps API using Javascript is that the objects you create function just as any other object or variable you would usually find in Javascript.

This means that you can easily push a new var into the marker. I have done this myself a couple of times and it works like a charm :)

Simply go :

var marker = new google.maps.Marker();
marker.timestamp = WHATEVER_YOU_WANT;
like image 105
Kasper Vesth Avatar answered Jun 29 '26 21:06

Kasper Vesth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!