php - Change googlemap marker image from database -


is there way this?

like, have data in db, , show data markers in googlemap api.

but want change marker image, same id db.

the name , description, showing correctly marker marker, want change marker image

my code:

  <html>  <head>  <meta http-equiv="content-type" content="text/html; charset=utf-8"/>  <title></title>  <link rel="stylesheet" type="text/css" href="style.css">  <script src="http://maps.google.com/maps/api/js?v=3&sensor=false" type="text/javascript"></script>  <script type="text/javascript">    var icon = new google.maps.markerimage('http://localhost/partytime/uploadedimages/davi.png',  new google.maps.size(50,50),   new google.maps.point(0,0),  new google.maps.point(0,0),  new google.maps.size(50,50));  var center = null;  var map = null;  var currentpopup;  var bounds = new google.maps.latlngbounds();  function addmarker(lat, lng, info) {  var pt = new google.maps.latlng(lat, lng);  bounds.extend(pt);  var marker = new google.maps.marker({  position: pt,  icon: icon,  map: map  });  var popup = new google.maps.infowindow({  content: info  //maxwidth: 300   });  google.maps.event.addlistener(marker, "click", function() {  if (currentpopup != null) {  currentpopup.close();  currentpopup = null;  }  popup.open(map, marker);  currentpopup = popup;  });  google.maps.event.addlistener(popup, "closeclick", function() {  map.panto(center);  currentpopup = null;  });  }  function initmap() {  map = new google.maps.map(document.getelementbyid("map"), {  center: new google.maps.latlng(0, 0),  zoom: 3,  maptypeid: google.maps.maptypeid.roadmap,  maptypecontrol: false,  maptypecontroloptions: {  style: google.maps.maptypecontrolstyle.horizontal_bar  },  navigationcontrol: true,  navigationcontroloptions: {  style: google.maps.navigationcontrolstyle.small  }  });  <?php  }  $query = mysql_query("select * localizacoes");  while ($row = mysql_fetch_array($query)){  $r =  explode( ',', $row['posicao'] );  $name=$row['nome'];  $lat = $r[0];  $lon = $r[1];   $dataevento = explode( '-', $row['dataevento'] );  $ano = $dataevento[0];  $mes = $dataevento[1];  $dia = $dataevento[2];   echo ("addmarker($lat, $lon,'<h1><b>$name</b></h1>$dia-$mes-$ano');\n");  }  ?>       }  </script>  </head>  <body onload="initmap()" style="margin:0px; border:0px; padding:0px;">  <div id="centro">  <div id="map">   </div>  </div>  </html> 

note: in code, put imagem localhost...this imagem refers id, , want show each image each id googlemap marker icon

see article: using php/mysql google maps: custom icons information how associate marker icons type field database.

from article:

custom icons

you can specify custom icons markers.

start creating associative array associates icons type strings: 'restaurant' or 'bar.' makes icons easy reference later when create markers xml.

var customicons = {   restaurant: {     icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png'   },   bar: {     icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png'   } }; 

Comments