title: Filter Google Maps map with a dropdown menu
body: <p>I have a Google Maps map generated from a database table. I would like to filter the marker with the help of two selections: Regione and Provincia, which are made in Ajax.</p>
  
  <p>My page:</p>
  
  <pre><code>&lt;head&gt;
      &lt;script type="text/javascript" src="jquery-1.3.2.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  jQuery(document).ready(function() {
  
  jQuery('#sel_regione').change(function(){
  
  
  
              var cont = jQuery('#sel_regione').attr('value');
              jQuery.post("selection.php", {regione_id:cont}, function(data){
              jQuery("#sel_provincia").empty();
              jQuery("div#result").empty();
              jQuery("#sel_provincia").prepend(data);
              });
              });
  
  jQuery('#sel_provincia').change(function(){
  
              var id_naz = jQuery('#sel_provincia').attr('value');
  
              jQuery.post("result.php", {provincia_id:id_naz}, function(data){
              jQuery("div#result").empty();
              jQuery("div#result").prepend(data);
              });
              });
  
  });
  &lt;/script&gt;
  &lt;?php $db = mysql_connect("miodb","user","pass");
       mysql_select_db("dbname", $db); ?&gt;
  
      &lt;script src="http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;key=APIKEY" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  
  var mioMarker = new google.maps.Marker({
  
                      map: map,
                      icon: mioLogo,
                      title:"mioTitle"
              });
  
      function createMarker(point,html) {
  
          var marker = new GMarker(point);
         GEvent.addListener(marker,"click",function(){ top.location = "#" }); 
         return marker;
        }
  
  
          function initialize() {
          if (GBrowserIsCompatible()) {
          var map = new GMap2(document.getElementById("map_canvas"),{ size: new GSize(580,400) } );
          map.removeMapType(G_HYBRID_MAP);
          map.setCenter(new GLatLng(43.036776,12.45758,0), 1);
                  map.setZoom(5);
          var mapControl = new GMapTypeControl();
          map.addControl(mapControl);
          map.addControl(new GLargeMapControl());
  
  
  
  
   &lt;?  $exe1="SELECT lat,lng FROM mytable";
       $result1 = mysql_query($exe1, $db)or die(mysql_error());  
       while(list($lat,$long) = mysql_fetch_row($result1)){ 
  
              echo "\n var point = new GLatLng(".$lat.",".$long.");\n";
              echo "var marker = createMarker(point,'');\n";
              echo "map.addOverlay(marker);\n";
              echo "\n";
      }
  ?&gt; 
  
  }
      }
  
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onload="initialize()" onunload="GUnload()"&gt;
  &lt;div id="regione"&gt;
  &lt;?php
  include_once 'option.class.php';
  $obj = new Option();
  $obj-&gt;ShowRegione();
  ?&gt;
  &lt;/div&gt;
  
  &lt;div id="provincia"&gt;
  Seleziona una provincia:&lt;br&gt;
  &lt;select id="sel_provincia" name="sel_provincia"&gt;&lt;option value="no"&gt;Scegli...&lt;/option&gt;
  &lt;/select&gt;
  &lt;/div&gt;
  
  &lt;div id="result"&gt;
  
  
  &lt;/div&gt;
  
          &lt;div id="map_canvas" style="width: 580px; height: 300px"&gt;&lt;/div&gt; 
  &lt;/body&gt;
  </code></pre>
  
  <p>option.class.php</p>
  
  <pre><code>&lt;?php
  class Option
  {
      public $conn;
  
          public function __construct()
          {
              $this-&gt;DbConnectAndSelect();
          }
  
          protected function DbConnectAndSelect()
          {
              include_once "db_config.php";
              $this-&gt;conn = mysql_connect($db_host,$username,$password);
              mysql_select_db($db_name, $this-&gt;conn);
              return TRUE;
          }
  
          public function ShowRegione()
          {
              echo 'Seleziona una regione:&lt;br&gt;';
              echo '&lt;select id="sel_regione" name="sel_regione"&gt;&lt;option value="no"&gt;Scegli...&lt;/option&gt;';
  
              $sql = "SELECT * FROM table_regione";
              $res = mysql_query($sql,$this-&gt;conn);
  
                  while($row = mysql_fetch_array($res))
                  {
                      echo '&lt;option value="' . $row['regione_id'] . '"&gt;' . $row['nome'] . '&lt;/option&gt;';
                  }
  
              echo '&lt;/select&gt;';
          }
  
          public function ShowProvincia()
          {
              if($_POST['regione_id'] == "no")
              {
                  die;
              }
  
  
              $sql = "SELECT * FROM table_provincia WHERE regione_id=$_POST[regione_id]";
              $res = mysql_query($sql,$this-&gt;conn);
                  echo'&lt;option value="no"&gt;Scegli...&lt;/option&gt;';
                  while($row = mysql_fetch_array($res))
                  {
                      echo '&lt;option value="' . $row['provincia_id'] . '"&gt;' . $row['nome'] . '&lt;/option&gt;';
                  }
  
  
          }
  
          public function ShowResult()
          {
                          $query = "SELECT * FROM miaTable WHERE provincia_id=$_POST[provincia_id]";
                          $risultati=mysql_query($query);
                          $num=mysql_numrows($risultati);
                          if ($num == 0)
                           {
                              echo "&lt;br&gt;&lt;br&gt; No records found";
                           }
              else
                          {
              echo '&lt;br&gt;&lt;br&gt;Trovati i seguenti record: &lt;br&gt; ';
                          $i=0;
                          while ($i &lt; $num) {
  
                           $denominazione=mysql_result($risultati,$i,"denominazione");
                           $indirizzo=mysql_result($risultati,$i,"indirizzo");
  
       echo "&lt;b&gt;$denominazione&lt;/b&gt;&lt;br&gt;$indirizzo&lt;br&gt;&lt;br&gt;";
  
       $i++;
  
                          }
                          }
          }
  }
  
  ?&gt;
  </code></pre>
  
  <p>file result.php</p>
  
  <pre><code>&lt;?php
  include_once 'option.class.php';
  $obj = new Option();
  $obj-&gt;ShowResult();
  ?&gt;
  </code></pre>
  
  <p>file selection.php</p>
  
  <pre><code>&lt;?php
  include_once 'option.class.php';
  $obj = new Option();
  $obj-&gt;ShowProvincia();
  ?&gt;
  </code></pre>
  
  <p>How I do this? Any help is really appreciated!</p>