Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2002
    Messaggi
    180

    db, php, marker google map

    Ciao a tutti,
    grazie al vostro aiuto sono quasi arrivato in fondo a quello che avevo in mente.

    Siamo al passaggio finale, vi riassumo il procedimento:
    Ho creato un db MySQL con una tabella markers che contiene alcuni punti con le loro coordinate.

    Attraverso una pagina menu_sel.html con menu a tendina preparo la query (con un parametro id) che poi passo al file select_sel.php che la esegue.

    Tutto ok, mi restituisce la tabella con il punto selezionato.
    --------------------------
    Ho poi integrato una parte che genera un xml a partire dalla query precedente ed ho messo sia la tabella che l'xml all'interno del ciclo while:

    guardando il codice di uscita vedo sia la tabella con il punto scelto che il marker xml per quel punto. Ok fino a qui.
    ecco il codice
    <html>
    <head><title>Recupero dati da una tabella di database</title></head>
    <body>

    <?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('gdb', $connection) or die ('database non selezionato : ' . mysql_error());

    $seltipo = $_POST['seltipo'];
    $query = "SELECT * FROM markers where id='$seltipo'";

    // invio la query
    $result = mysql_query($query);

    // controllo l'esito
    if (!$result) {
    die("Errore nella query $query: " . mysql_error());
    }

    echo "

    $query </p>";
    echo '
    <table border="1" bgcolor="#FFFFFF">
    <tr bgcolor="#CCCCCC">
    <th>id</th>
    <th>denom</th>
    <th>indir</th>
    <th>lat</th>
    <th>long</th>
    <th>tipomarker</th>
    </tr>';

    while ($row = mysql_fetch_assoc($result)) {
    $id = htmlentities($row['id']);
    $den = htmlentities($row['denom']);
    $ind = htmlentities($row['indirizzo']);
    $lt = htmlentities($row['lat']);
    $lg = htmlentities($row['long']);
    $mrk = htmlentities($row['tipomarker']);


    echo "<tr>
    <td>$id</td>
    <td>$den</td>
    <td>$ind</td>
    <td>$lt</td>
    <td>$lg</td>
    <td>$mrk</td>
    </tr>";

    $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 '</table>';
    echo $dom->saveXML();

    // libero la memoria di PHP occupata dai record estratti con la SELECT
    mysql_free_result($result);

    // chiudo la connessione a MySQL
    mysql_close();
    ?>



    </body>
    </html>

    ------------------------------------------------

    Ecco ora il punto dolente che non torna:
    ora devo integrare il tutto con una pagina che visulaizza i marker relativi alla selezione sulla mappa Google.

    Il codice per rappresentare i marker ce l'ho, e funziona a partire dal file creaxml.php, ma io vorrei che prendesse i dati dal mio file relativo alla selezione precedente, eccolo:
    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);

    // è qui che non deve leggere da creaxml.php ma dalla selezione precedente select_sel.php
    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[i].getAttribute("denom");
    var indirizzo = markers[i].getAttribute("indirizzo");
    var tipomarker = markers[i].getAttribute("tipomarker");
    var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
    parseFloat(markers[i].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>
    -------------------------

    riassumendo quindi:
    -seleziono una voce del menu a tendina di menu_sel.html
    -passo il parametro per la query al file select_sel.php che genera la tabella relativa alla selezione e la riga xml per la selezione effettuata
    -sotto la tabella vorrei vedere la mappa di google con i marker selezionati (e non ci riesco)

    Grazie mille e scusate della mail kilometrica, ma altrimenti non riuscivo a spiegarmi....

  2. #2
    Utente di HTML.it
    Registrato dal
    Apr 2002
    Messaggi
    180
    ...forse qualcosa ho risolto....
    il problema è che mi servirebbero 3 pagine:
    - una pagina html iniziale di selezione dati con tendina e che passi il parametro al creaxml.php
    - la pagina creaxml.php che recepisca tale parametro (ok funziona)
    - la pagina di presentazione dati (gmap.htm che funziona)

    vediamo cosa ho fatto:

    creaxml.php seleziona, tra tutti i possibili, il record giusto a partire dall'id corrispondente: il problema è che devo passare questo parametro,id='xxx', da una maschera iniziale

    <?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('gdb', $connection) or die ('database non selezionato : ' . mysql_error());

    // Seleziona tutte le righe della tabella con i markers
    // devo passare questo parametro,id='1', da una maschera
    $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();

    ?>

    -------------------------------------------
    questo file gmap.htm visualizza il marker scelto dal xml precedente e funziona:

    <!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[i].getAttribute("denom");
    var indirizzo = markers[i].getAttribute("indirizzo");
    var tipomarker = markers[i].getAttribute("tipomarker");
    var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
    parseFloat(markers[i].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">

    </body>
    </html>
    -----------------------------
    la pagina iniziale di ricerca è questa, che passa il parametro $seltipo alla query:

    <!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">Selezione dati dal database</td>
    </tr>
    <form name="elab" method="post" action="./creaxml.php">
    <tr>
    <td align="center" valign="middle" class="CellaDati">

    Seleziona un id:
    <select name="seltipo" id="seltipo">
    <option value="1" >pisa</option>
    <option value="2" >firenze</option>
    <option value="3" >livorno</option>
    </select>
    </p>
    </td>
    </tr>
    <tr align="center" valign="middle">
    <td class="CellaIntest"> <input type="submit" value="Visualizza dati "> </td>
    </tr>
    </form>
    </table>




    </body>

    </html>

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2002
    Messaggi
    180
    ricominciamo, vediamo così:
    -pagina principale da cui seleziono d amenu a tendina e che passa il parametro al generatore di xml:
    <!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[i].getAttribute("denom");
    var indirizzo = markers[i].getAttribute("indirizzo");
    var tipomarker = markers[i].getAttribute("tipomarker");
    var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
    parseFloat(markers[i].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>
    <table width="770" border="1" align="center" cellpadding="10" cellspacing="3">
    <tr align="center" valign="middle">
    <td bgcolor="#CCCCCC" class="CellaIntest">Selezione dati dal database</td>
    </tr>
    <form name="elab" method="post" action="./creaxml.php">
    <tr>
    <td align="center" valign="middle" class="CellaDati">

    Seleziona un id:
    <select name="seltipo" id="seltipo">
    <option value="1" >pisa</option>
    <option value="2" >firenze</option>
    <option value="3" >livorno</option>
    </select>
    </p>
    </td>
    </tr>
    <tr align="center" valign="middle">
    <td class="CellaIntest"> <input type="submit" value="Visualizza dati "> </td>
    </tr>
    </form>
    </table>




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

    </body>
    </html>
    --------------------------------
    pagina che crea l'xml:
    <?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('gdb', $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();

    ?>
    ----------------------------
    ma non funziona!!!!!!!!!!
    chi mi corregge please?

    grazie mille

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.