php - Filter Google Maps map with a dropdown menu -
i have google maps map generated database table. filter marker of 2 selections: regione , provincia, made in ajax.
my page:
<head> <script type="text/javascript" src="jquery-1.3.2.js"></script> <script type="text/javascript"> 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); }); }); }); </script> <?php $db = mysql_connect("miodb","user","pass"); mysql_select_db("dbname", $db); ?> <script src="http://maps.google.com/maps?file=api&v=2&key=apikey" type="text/javascript"></script> <script type="text/javascript"> 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()); <? $exe1="select lat,lng 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"; } ?> } } </script> </head> <body onload="initialize()" onunload="gunload()"> <div id="regione"> <?php include_once 'option.class.php'; $obj = new option(); $obj->showregione(); ?> </div> <div id="provincia"> seleziona una provincia:<br> <select id="sel_provincia" name="sel_provincia"><option value="no">scegli...</option> </select> </div> <div id="result"> </div> <div id="map_canvas" style="width: 580px; height: 300px"></div> </body>
option.class.php
<?php class option { public $conn; public function __construct() { $this->dbconnectandselect(); } protected function dbconnectandselect() { include_once "db_config.php"; $this->conn = mysql_connect($db_host,$username,$password); mysql_select_db($db_name, $this->conn); return true; } public function showregione() { echo 'seleziona una regione:<br>'; echo '<select id="sel_regione" name="sel_regione"><option value="no">scegli...</option>'; $sql = "select * table_regione"; $res = mysql_query($sql,$this->conn); while($row = mysql_fetch_array($res)) { echo '<option value="' . $row['regione_id'] . '">' . $row['nome'] . '</option>'; } echo '</select>'; } public function showprovincia() { if($_post['regione_id'] == "no") { die; } $sql = "select * table_provincia regione_id=$_post[regione_id]"; $res = mysql_query($sql,$this->conn); echo'<option value="no">scegli...</option>'; while($row = mysql_fetch_array($res)) { echo '<option value="' . $row['provincia_id'] . '">' . $row['nome'] . '</option>'; } } public function showresult() { $query = "select * miatable provincia_id=$_post[provincia_id]"; $risultati=mysql_query($query); $num=mysql_numrows($risultati); if ($num == 0) { echo "<br><br> no records found"; } else { echo '<br><br>trovati seguenti record: <br> '; $i=0; while ($i < $num) { $denominazione=mysql_result($risultati,$i,"denominazione"); $indirizzo=mysql_result($risultati,$i,"indirizzo"); echo "<b>$denominazione</b><br>$indirizzo<br><br>"; $i++; } } } } ?>
file result.php
<?php include_once 'option.class.php'; $obj = new option(); $obj->showresult(); ?>
file selection.php
<?php include_once 'option.class.php'; $obj = new option(); $obj->showprovincia(); ?>
how this? appreciated!
Comments
Post a Comment