views:

371

answers:

1

How can I display a number in the marker on a google map? I want to do server side clustering and I need to display how many points the cluster represents.

+1  A: 

You can use labels over markers, here is a tutorial about GIcon.label.

You can also use GMarker.openInfoWindow.

Tip: This is the best tutorial I found about google maps api (of course after Official documentation)

Sameh Serag
Is there a way to do this using Google Maps Javascript API V3?
User
Also from the tutorial I'm not clear how do I set arbitrary text for the label (e.g. to give the label)
User
I did not try V3, but by default, google supports backward compatibility. The idea behind icon labels is to create 2 images: one for the icon itself (if you don't need to use the default icon) and another image that overlays the first one. This second image could be prepared to contain some text, which is then used as the marker label. To create this label on-the-fly you have to create this image at run-time, and of course this will be at server side, this is not hard if you are using ASP.NET for instance.
Sameh Serag
As for v3, I found this sample (MarkerClusterer) but I did not try it: http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/examples/advanced_example.html
Sameh Serag
If you look at MarkerClusterer (and I've used this project) they create these clusters with numbers on them and they're not being generated server side. Looking at the code however, I'm not sure exactly how they're creating the numbers on the markers.
User
Here is the source code of the MarkerClusterer: http://gmaps-utility-library-dev.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer.jsFind the "ClusterMarker_" function in code, and see how it works. From the quick check of the code, they are representing the marker as a DIV with certain style/image, and the number of markers is its innerHTML.
Sameh Serag