On 26 April 2011 16:38, happyneil <[email protected]> wrote:
> /* Here is where I retrieve all the values */
>
>        $latLongSize = sizeof($lat)-1;
>
> for($i=0; $i<=$latLongSize; $i++){ ?>
>
>        var markers<?php echo $i; ?> = createMarker(new GLatLng(<?php echo
> $lat[$i];?>, <?php echo $long[$i]; ?>));
>                map.addOverlay(markers<?php echo $i; ?>);
>        <?php } ?>
>
>                var markerCluster = new MarkerClusterer(map, markers);
>      }
>    }
>
> I think the problem may lie with how the data is feed into the
> markerCluster variable. At the moment my code is outputting points
> from my MSSQL database but not clustering the points.

What the above php snippet will do is provide Javascript like

var markers1 = createMarker(new GLatLng(51,1));
map.addOverlay(markers1);
var markers2 = createMarker(new GLatLng(51,2));
map.addOverlay(markers2);
var markers3 = createMarker(new GLatLng(51,3));
map.addOverlay(markers3);
var markerCluster = new MarkerClusterer(map, markers);

So you are creating three individual markers and adding each of them
to the map, and then creating a markerCluster with whatever "markers"
is -- probably undefined.

NB: "markers" in the last line here is not the same as "markers" in
your createMarker function, because of the var keyword in the
function. That keeps the variable local to the function. Even if you
take the var out, markers would only ever be a single marker.

What you probably want is Javascript which looks like

var markers[1] = createMarker(new GLatLng(51,1));
var markers[2] = createMarker(new GLatLng(51,2));
var markers[3] = createMarker(new GLatLng(51,3));
var markerCluster = new MarkerClusterer(map, markers);

making sure that "markers" is in the right scope, and doing something
with the markerCluster you create.

Better still would be

markers.push(createMarker(new GLatLng(51,1)));
markers.push(createMarker(new GLatLng(51,2)));
markers.push(createMarker(new GLatLng(51,3)));
var markerCluster = new MarkerClusterer(map, markers);

which should simplify the php you need.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps API V2" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-api?hl=en.

Reply via email to