-1

I wish to dynamically generate a google map based on details from an xml feed which then refers to a database to translate city names into map coordinates. I'm OK with that but there may be 10 or even 50 at a specific city and therefore have the same coordinates. I cannot be more specific with the location because I do not know it. My question is does anyone have an idea how I can display the markers without them hiding each other? My thoughts are some kind of popup list, (although I can't think how to code it) or on offset added to the coordinates to change them slightly. Thoughts appreciated. My markers are created using php and added as one string.

$markers = $markers . "['<a href=\"". $url . "\">".$type."</a>'," . $lat . "," . $long . ",". $num."],";      
var locations = [ php echo $markers /php];
sharon
  • 55
  • 7
  • Have you checked here http://stackoverflow.com/questions/3548920/google-maps-api-v3-multiple-markers-on-exact-same-spot – BigScar Apr 05 '15 at 21:02
  • No, that one didn't come up in the similar options for some reason. It looks promising, I'll let you know when I've studied it and tried it. – sharon Apr 05 '15 at 21:11
  • I am struggling to understand this to be honest because my javascript is bad. I also add markers to the map using one php string echoed in the javascript. Does anyone have other ideas? – sharon Apr 06 '15 at 09:43

1 Answers1

0

If it helps anyone I have found possible temporary solution. It's not one for the purists but I have simply randomized the last four digits of the location. It seems to work good enough for me at the moment and there is enough separation when zoomed.

$lat = get_lat($town, $state);
$long = get_long($town, $state);
$temp_long = mt_rand(1000,9999);
$temp_lat = mt_rand(1000,9999);
$lat = substr($lat, 0, -4) . $temp_lat;
$long = substr($long, 0, -4) . $temp_long;
$markers = $markers . "['<a href=\"". $url . "\">".$type."</a>'," . $ lat . "," . $long . ",". $i."],";

Thanks for the link anyway.

sharon
  • 55
  • 7
  • This problem must come up again and again and I'm wondering if its more of a data presentation problem than a programming problem. I was thinking of counting the markers at each location and placing one "supermarker" saying "50 more at this location" with links in the info box to the individual subjects. – BigScar Apr 06 '15 at 12:44
  • I use the markers as clickable links (via a small popup box) so I need the facility to see each marker and for it to be clickable. I have no doubt there are prettier solutions but if I can't understand them then it just makes enhancement later so much more difficult. I think eventually google will resolve it themselves. – sharon Apr 06 '15 at 15:59