Markers su google map da selezione

vincentand

Nuovo Utente
3 Giu 2009
1
0
0
Ciao a tutti,
cerco di spiegare il mio problema:
ho un file menu_sel.html che contiene un menu a tendina nel quale l'utente sceglie un parametro e cliccando il tasto "visualizza" richiama un file creaxml.php passandogli il parametro scelto alla query.
Infatti quando clicco visualizza, si visualizza il risultato della query (in particolare viene generato a video il risultato del file xml relativo alla selezione effettuata).

Il problema è che ho un altro file gmap.htm che produce dei marker sulla mappa di google a partire dal file creaxml.php: il problema è che non so come integrarlo in modo che questo file htm possa essere lanciato direttamente dal file menu_sel.html iniziale.
-----------------------------------------------
Insomma vorrei che dalla maschera inziale menu si scegliesse il parametro e si potesse lanciare la mappa con visualizzati i marker prodotti dal file xml, relativi alla selezione effettuata.
-----------------------------------------------
Spero di essere stato chiaro.........

vi faccio l'esempio dei files a blocchi:
menu.html
<html>
<body>
menu tendina <form name="elab" method="post" action="./creaxml.php">
e passa parametro "selezione"
</body>
</html>
---------------------
creaxml.php
<?php
$query = "SELECT * FROM markers WHERE id='$selezione'";
while ($row = @mysql_fetch_assoc($result)){
crea file xml}
echo $dom->saveXML();
?>
------------------------
gmap. htm
<head>
<script type="text/javascript">
GDownloadUrl("creaxml.php", function(data) {
crea markers dal file creaxml.php
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 800px; height: 600px"></div>
</body>
</html>

-----------------
ti allego ora i 3 sorgenti:
menu_sel.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
<title>
interrogazione dBase
</title>
<style type="text/css">
<!--
.Stile1 {color: #FFFFFF}
-->
</style>
</head>

<body>
<table width="770" border="1" align="center" cellpadding="10" cellspacing="3">
<tr align="center" valign="middle">
<td bgcolor="#CCCCCC" class="CellaIntest"><strong>Selezione dati dal database</strong></td>
</tr>
<form name="elab" method="post" action="./creaxml.php">
<tr>
<td align="center" valign="middle" class="CellaDati"><p>Seleziona un id:
<select name="seltipo" id="seltipo">
<option value="1" >firenze</option>
<option value="2" >pistoia</option>
<option value="3" >pisa</option>
</select>
</p>
</td>
</tr>
<tr align="center" valign="middle">
<td class="CellaIntest"> <input type="submit" value="Visualizza dati "> </td>
</tr>
</form>
</table>

<br>

</body>

</html>
---------------------------
creaxml.php
<?php

$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);


// Si connette al database
$connection= mysql_connect ('localhost', 'root', '') or die('Non connesso : ' . mysql_error());
$db_selected = mysql_select_db('mappa', $connection) or die ('database non selezionato : ' . mysql_error());

// Seleziona tutte le righe della tabella con i markers
$seltipo = $_POST['seltipo'];
$query = "SELECT * FROM markers WHERE id='$seltipo'";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}

header("Content-type: text/xml");

// Iterate through the rows, adding XML nodes for each

while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);

$newnode->setAttribute("name",$row['denom']);
$newnode->setAttribute("address", $row['indirizzo']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("long", $row['long']);
$newnode->setAttribute("type", $row['tipomarker']);

}

echo $dom->saveXML();

?>
-------------------------
gmap.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Visualizzazione markers su Google Map tramite MySQL e PHP</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAArSysGIurcK7dOMZla-7TExQSXE4ITa1YzwIbIoQt-CisjCLm8xS2jytkVj9gPuB1NWF-zZMCsCPqMA"
type="text/javascript"></script>
<script type="text/javascript">


function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(44.0750963, 10.700323), 8);

GDownloadUrl("creaxml.php", function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var denom = markers.getAttribute("denom");
var indirizzo = markers.getAttribute("indirizzo");
var tipomarker = markers.getAttribute("tipomarker");
var point = new GLatLng(parseFloat(markers.getAttribute("lat")),
parseFloat(markers.getAttribute("long")));
var marker = createMarker(point, denom, indirizzo, tipomarker);
map.addOverlay(marker);
}
});
}
}


function createMarker(point, denom) {
var marker = new GMarker(point);

GEvent.addListener(marker, 'mouseover', function() {
marker.openInfoWindowHtml(denom);
});
return marker;
}

</script>
</head>

<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 800px; height: 600px"></div>

</body>
</html>
---------------------


grazie della disponibilità
 

Discussioni simili