0
votes

I'm using Google Maps API v3. My code takes objects (name, lat, lng, and type) from MySql database and markers their on map. That works for me fine. But I want to make different markers depending on them type. So here is my markers options:

var iconBaznycios = new google.maps.MarkerImage('http://labs.google.com/ridefinder/images/mm_20_blue.png');

var iconMuziejai = new google.maps.MarkerImage('http://labs.google.com/ridefinder/images/mm_20_red.png');

var customIcons = [];
customIcons["Baznycios"] = iconBaznycios;
customIcons["Muziejai"] = iconMuziejai;

And here is my function i want to pass my markers array:

function addMarker(lat, lng, info, type) {

  var pt = new google.maps.LatLng(lat, lng);
  bounds.extend(pt);
  var marker = new google.maps.Marker({
             position: pt,
             icon: customIcons[type],
             map: map,

  });

and maybe there is something to do with this line in php script:

echo ("addMarker($lat, $lng,'<b>$name</b><br/> $type');\n");

any ideas how to make it work my way?

1

1 Answers

0
votes

I think this PHP line needs to be changed: looks like a quote is misplaced and missing a comma.

echo ("addMarker($lat, $lng,'<b>$name</b><br/>', '$type');\n");

From my experience, icon inside new google.maps.Marker only needs the URL. It's just shorter, MarkerImage should also work.

var customIcons = [];
customIcons["Baznycios"] = 'http://labs.google.com/ridefinder/images/mm_20_blue.png'
customIcons["Muziejai"] = 'http://labs.google.com/ridefinder/images/mm_20_red.png'