I’m trying to create google maps markers to show events, however I have the issue that sometimes the events take place at the same location – therefore markers overlap.
I thought if it would be possible to collapse results into one if more rows had the same venues.VENUE_LOCATION.
So, instead of producing an xml like this:
<marker lat="48.153938" lng="17.108459" venue="2" html="Event 1 - Jan 1" />
<marker lat="48.153938" lng="17.108459" venue="2" html="Event 2 - Jan 10" />
<marker lat="48.153938" lng="17.108459" venue="2" html="Event 3 - Jan 18" />
<marker lat="49.459843" lng="17.564821" venue="5" html="Event 55 - Jan 4" />
<marker lat="49.459843" lng="17.564821" venue="5" html="Event 70 - Jan 10" />
I would have one marker which would contain info for all of the markers in that location.
<marker lat="48.153938" lng="17.108459" venue="2" html="Event 1 - Jan 1<BR>Event 2 - Jan 10<BR>Event 3 - Jan 18" />
<marker lat="49.459843" lng="17.564821" venue="5" html="Event 55 - Jan 4<BR>Event 70 - Jan 10" />
Any idea how I could do that? Here is my current php code
$query = "SELECT
events.ID,
events.EVENT_NAME,
events.start_datetime,
events.end_datetime,
events.VENUE_LOCATION,
venues.VENUE_NAME,
venues.VENUE_LOCATION,
venues.LAT,
venues.LNG,
GROUP_CONCAT(music_styles.MUSIC_STYLE_NAME) AS MUSIC_STYLE_NAME
FROM events
INNER JOIN venues
ON events.VENUE_LOCATION = venues.ID
INNER JOIN events_music_styles
ON events.ID = events_music_styles.event_id
INNER JOIN music_styles
ON events_music_styles.music_style_id = music_styles.id
WHERE start_datetime >= '$phpFromDate'
AND start_datetime <= '$phpToDate'
";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
echo '<markers>';
if(mysql_num_rows($result) > 0)
{
while ($row = @mysql_fetch_assoc($result))
{
echo '<marker ';
echo 'event_id="' . parseToXML($row['ID']) . '" ';
echo 'lat="' . parseToXML($row['LAT']) . '" ';
echo 'lng="' . parseToXML($row['LNG']) . '" ';
echo 'venue="' . parseToXML($row['VENUE_LOCATION']) . '" ';
echo '/>';
}
}
echo '</markers>';
Thanks!
Try to modify your SQL query in line with
GROUP_CONCAT:Add also
GROUP BYstatement at the end of your query:Then when you print marker tags out, add
htmlattribute:Desired code: