MarkerClusterer won't cluster!

248 views
Skip to first unread message

Ashwin

unread,
Nov 15, 2011, 12:00:31 PM11/15/11
to Google Maps JavaScript API v3
Hello there,

I'm trying to get MarkerClusterer to work on a very simple example. I
have 100 data points on my map, but they won't seem to cluster. You
can see the sample at www.ashwinbalu.com.

Here's the (very!) basic code I'm using:


<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var myOptions = {
zoom: 4,
center: new google.maps.LatLng(0,0),
mapTypeId: google.maps.MapTypeId.ROADMAP,
}
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);

var markers = [];
for (var i = 0; i < 100; i++) {
var myLatlng = new google.maps.LatLng(i,i);
var marker = new google.maps.Marker({position: myLatlng});
markers.push(marker);
marker.setMap(map);
}
var mc = new MarkerClusterer(map, markers);
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>

geoco...@gmail.com

unread,
Nov 15, 2011, 3:22:39 PM11/15/11
to Google Maps JavaScript API v3
On Nov 15, 9:00 am, Ashwin <im.ash...@gmail.com> wrote:
> Hello there,
>
> I'm trying to get MarkerClusterer to work on a very simple example. I
> have 100 data points on my map, but they won't seem to cluster. You
> can see the sample at

http://www.ashwinbalu.com

Check your javascript console, I get this error:
====================================================
Error: MarkerClusterer is not defined
Source File: http://www.ashwinbalu.com/
Line: 29
====================================================

(you haven't included the MarkerCluster script)

-- Larry

Ashwin

unread,
Nov 16, 2011, 8:47:47 AM11/16/11
to Google Maps JavaScript API v3
I didn't realize I had to include an external script. How do I do
this? (I don't think I saw this in any of the given examples.)

geoco...@gmail.com

unread,
Nov 16, 2011, 8:57:07 AM11/16/11
to Google Maps JavaScript API v3
On Nov 16, 5:47 am, Ashwin <im.ash...@gmail.com> wrote:
> I didn't realize I had to include an external script. How do I do
> this? (I don't think I saw this in any of the given examples.)

Look at the examples again.

The script is here:

http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js

(unless you want to use the "compiled" version, which is in the same
place)

-- Larry

pkh80

unread,
Feb 9, 2012, 2:28:47 PM2/9/12
to google-map...@googlegroups.com
MarkerCluster still seems broken for newer gmaps. I took a copy of this test script and put it on the zoom level that's broken:


Zoom in or out and clusters appear. I have had similar problems while using other datasets and conditions.

Rossko

unread,
Feb 9, 2012, 2:39:35 PM2/9/12
to Google Maps JavaScript API v3
> http://www.nwkite.com/gmapstest.html
> Zoom in or out and clusters appear.

I don't get a map at all in IE, probably because you load the
MarkerClusterer script before the API which it extends.

Suprisingly, I see some blue, some yellow clusters under FF browser.

pkh80

unread,
Feb 9, 2012, 2:43:12 PM2/9/12
to google-map...@googlegroups.com
Ok I changed the load order - I should have mentioned I am testing in Chrome and Firefox. They both exhibit the same result for me.

I opened a ticket here:


Please star the issue if you are having the same problem.

pogue5

unread,
Feb 9, 2012, 2:53:26 PM2/9/12
to google-map...@googlegroups.com
if you set your LatLng to (i,i), how is this supposed generate all the latitudes and longitudes? Just curious...

geoco...@gmail.com

unread,
Feb 9, 2012, 2:58:37 PM2/9/12
to Google Maps JavaScript API v3
On Feb 9, 11:43 am, pkh80 <pholm...@gmail.com> wrote:
> Ok I changed the load order - I should have mentioned I am testing in
> Chrome and Firefox. They both exhibit the same result for me.
>
> I opened a ticket here:
>
> http://code.google.com/p/gmaps-api-issues/issues/detail?id=3914&thank...

That is too bad. The problem is this line in your code:
marker.setMap(map);

At least that is why the markers are displayed.

-- Larry

Rossko

unread,
Feb 9, 2012, 3:17:31 PM2/9/12
to Google Maps JavaScript API v3
> Please star the issue if you are having the same problem.

The problem is that you are not using the clusterer correctly.
Don't put your markers on the map yourself, as you want the clusterer
to manage them for you.
Reply all
Reply to author
Forward
0 new messages