Help with Google Maps Marker cluster from MSSQL database

Hi there,

Is there anyone that can help me with this some code. Basically I am currently outputting markers retrieved from my MSSQL database onto a Google Map. Unfortunately I need to output thousands of these markers and I came across the solution of marker clustering… The tutorial can be found here. I am having a lot of difficulty trying to work my code into the tutorial example. Can anyone give advice or provide sample code on how to approach fixing the code?

Cheers,

Neil

The code is below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
  Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  
        <?php
		/*data base connection */

		DATABASE CONNECTION
		
		/* SQL query */
		$tsql = ("SELECT TOP 100 gps_lat
				,gps_long
				FROM DATABASE");
  
		$result = sqlsrv_query($conn,$tsql);
	
	/*	CHECK FOR ERRORS FROM QUERY	*/
		if( $result === false)
		{
			echo "Error in query preparation/execution.\
";
			die( print_r( sqlsrv_errors(), true));
		}  
  ?>  
  
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html;
    charset=utf-8"/>
    <title>Google Maps JavaScript API Example</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true_or_false&amp;key=ABQIAAAAFdAFQ5eUeLToBjop7wxvVRQwhZZS-c1L0GQSo2zewspgIUCbcBQLESvgR7pk_2Z2FMWsfROoCbyJrw" type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(
        document.getElementById("map"));
        map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.addMapType(G_SATELLITE_3D_MAP);
        map.setCenter(
        new GLatLng(34.89438, -114.15069), 8);
		
	/*	THIS IS CREATING A MARKER FOR EVERY LATITUDE AND LONGITUDE FOUND
	*/
    function createMarker(point, text, title) {
          var marker =
          new GMarker(point,{title:title});
          return marker;
        }
<?php

 /*		HERE IS WHERE THE RESULTS ARE COLLECTED
 */
  	$lat=array();
	$long=array();
	while($points = sqlsrv_fetch_array($result)) {
	$lat[] = $points['gps_lat'];
	$long[] = $points['gps_long'];
	}

	
	$latLongSize = sizeof($lat)-1;

for($i=0; $i<=$latLongSize; $i++){ ?>
		
	var marker<?php echo $i; ?> = createMarker(new GLatLng(<?php echo $lat[$i];?>, <?php echo $long[$i]; ?>));	
		map.addOverlay(marker<?php echo $i; ?>);
 <?php } ?>
 /*
	I THINK THAT THE PROBLEM LIES WITH THE CODE BELOW... I DO NOT UNDERSTAND HOW TO ALTER IT TO CLUSTER THE DATA COLLECTED
 */
 
	  for (var ii = 0; i < 100; ++i) {
      var latlng = new GLatLng(data.photos[i].latitude, data.photos[i].longitude);
      var marker = new GMarker(latlng);
      markers.push(marker);
		}
		var markerCluster = new MarkerClusterer(map, markers);
      }
    }
    //]]>
    </script>
	


<h1>Header</h1>
  </head>
  <body onload="load()" onunload="GUnload()">
  
  
    <div id="map"
    style="width: 500px; height: 300px"></div>
	
	<?php

/* Close the connection. */
sqlsrv_close( $conn);


?>
  </body>
</html>

I will be honest with you, that seems to be mostly a JS question, and for such a specialized subject you are really better off going to the dedicated Google Maps group Gmaps v2 and asking questions - or, searching for answers.

Also, you seem to be using Gmaps v2 which has been largely replaced by the much better (IMO) Gmaps v3 - you do not need to apply for a key or submit a key :wink:

Gmaps v3 group.

Maybe there is someone on here with Gmaps v2 experience, but to me MarkerClusterer is an add-on to Gmaps and I cannot see where you have included the file (<script src=“markerclusterer.js”>) - maybe that is the key information you have not grasped?

(shameless plug: Upgrade to Gmaps v3 - Oily rag view)

Thank you Cups for your very quick response!! I shall try what you suggested.

Many thanks for your time!

Cheers,

Neil