Skip to content
Advertisement

marker cluster locations from database

i have been useing a map with markers from sql db and would like to add marker clusters as i get more markers.

on it self the code for the map and the code for the marker cluster from https://developers.google.com/maps/documentation/javascript/marker-clustering#maps_marker_clustering-javascript works fine, i have tried to combain them and keep geting a map with no markers .

this is the cluster map from google which works fine

JavaScript

this is the map i use with db markers and works fine

JavaScript

this is what i have tried – imalementing the db markers in the cluster map with no sucsses

JavaScript

this is the server php query for locations

JavaScript

Advertisement

Answer

Simplest solution, push your markers into an array when you create them, create a MarkerClusterer using that array.

  1. create an array to hold the markers (rather than an object), change:

    JavaScript

to:

JavaScript
  1. in the loop that creates your markers, push them onto that array:

    JavaScript
  2. after the loop is complete, create the MarkerClusterer using that array (the same code as in the example):

    JavaScript

proof of concept fiddle

screenshot of resulting map

code snippet:

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement