“Location matters!” … but do some locations matter more than others?
by Steve Emmons
GPS, Code May 1st, 2008Google Maps is an awesome resource for web-based GPS-tracking applications. And with so many ways to collect GPS locations these days, it makes mapping those GPS locations fast and simple. But sometimes, you can have so many GPS locations on a Google Map that it can be hard to see the one you want.
The GMaps API has tools to control what location markers you see, but the default options may not be what you want or expect. You can find many examples on the web on how to include a GMap using whatever tools you favor, but eventually, you will probably use Javascript to create a GMarkerManager and use “addMarker” or “addMarkers” to put GMarker objects in it either one at a time or as an array, respectively. So far so good…
But if you read the fine print, you will discover that a collection of GMarker objects, no matter what order you create them in, are placed on the map in such a way that the “southerly” markers are on top of the “northerly” markers. That means that if you have a sequence of markers representing the locations of a car, for example, that is traveling from south to north, then depending on your zoom level and the frequency of GPS reports, you might find the older GPS location markers showing ON TOP OF the newer ones.
Now, to me, the intuitive thing is to show markers on the map the same way you would if you were using a pen and paper, plotting dots as you got them. If so, you would see put ink for the newest dot ON TOP OF anything else that is already on the map. Right?
So now what? Well, in the same fine print about the default marker display — the GMarkerOptions class documentation, to be specific — you will find that GMarkers can have an attribute called the “zIndexProcess” which is a Javascript Function. This means you can override the order in which the markers are displayed.
Now, in my case, I have a simple “for” loop to create a set of marker. The loop has an index to enumerate my GPS locations and create GMarker objects to add to a GMarkerManager object for my map. I simply use this index to create a “zIndexProcess” function when I create the GMarker. It works like a champ!
Here’s some code that shows how it works. Mouse over the points to see the times. The “NEWEST” and “OLDEST” points are so labeled. Note that the trail of GPS location travels from south to north, so the “northerly” locations should be on top, but are NOT by default…
HINT: If you right-click in the titles of the maps you can “View Source” in most browsers to see how this code works. It’s self containted, and you can experiment with your own copy.


May 5th, 2008 at 8:43 am
What a great find, thanks for sharing. I love the fact that the most recent location reading is on top, but if only it was as visually appealing as the default z-order approach. When zoomed out, the override approach makes it look as though the pins are stuck into each other. Maybe the use of marker aggregation or possibly a different icon could provide more visual clarity?
May 5th, 2008 at 12:21 pm
For tracking - markers seem an artificial construct of the location sampling. It would be better to use a Line with a marker to show just the most recent location. For leaving icons of these samples I would agree that a stemmed marker isn’t really suitable, and instead a small dot would be better (and still using this z-order modification)