I am placing markers on a Google Map based on the longitude and latitude coordinates that are coming from a database, this part was fine until I came across the problem when 2 or more coordinates where identical, and my markers where stacked on top of one another.
The solution I am trying to accomplish is to group my results by the longitude and latitude within the array itself. And this way within the info window itself, I can place all the addresses and details with identical coordinates. During tests, I was capable of coming with the following results.
Longitude: 80.3158, Latitude:
address1
Longitude: 80.3119, Latitude:
address2
address3
address4
Longitude: 80.3107, Latitude:
address5
Longitude: 80.3036, Latitude:
address6
The script to get those results…
$results = mysql_unbuffered_query("SELECT address, lon, lat FROM locations");
$set = array();
while ($result = mysql_fetch_object($results))
{
$set[$result->lon][] = $result;
}
mysql_free_result($results);
foreach ($set as $lon => $records)
{
print "<b>Longitude: {$lon}, Latitude: {$lat}</b><br />\n";
foreach ($records as $record)
{
print "{$record->address}<br />\n";
}
print "<br /><br />";
}
The part I am having problems with is getting the Latitude into my groups. Is there a way of getting multiple values from my array? $set[$result->lon][] = $result, and sorting it out in my foreach?