IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

APIs Google Discussion :

Comment afficher un calque généré par un fichier php [Google Maps]


Sujet :

APIs Google

  1. #1
    Nouveau membre du Club
    Inscrit en
    Septembre 2005
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Septembre 2005
    Messages : 45
    Points : 27
    Points
    27
    Par défaut Comment afficher un calque généré par un fichier php
    Bonjour,

    Je voudrais afficher une carte sur laquelle j'ajouterais un calque en kml crée par un fichier php.
    Si la balise google.maps.KmlLayer pointe sur un exemple de fichier kml, celui-ci s'affiche sans problème (ou presque) mais si c'est vers mon fichier php sensé créer le fichier kml, je vois juste la carte.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
     
    <script type="text/javascript">
    var myMap;
     
    window.onload = function () {
       var myLatlng = new google.maps.LatLng(42.7, 0.7);
       var myOptions = {
          zoom: 7,
          center: myLatlng,
          mapTypeId: google.maps.MapTypeId.TERRAIN
       }
       myMap = new google.maps.Map(
          document.getElementById('carte'),
          myOptions
          );
    }
     
    function affiche() {
     
       var myLayer = new google.maps.KmlLayer("http://w3.dtp.obs-mip.fr/RSSP/WEB_2.2/LaSismicite/txt2KML.php?<?php echo rand (1,100) ?>");
     
    //   var myLayer = new google.maps.KmlLayer("http://w3.dtp.obs-mip.fr/RSSP/WEB_2.2/LaSismicite/temp.kml?<?php echo rand (1,100) ?>");
     
       myLayer.setMap(myMap);
    }
    </script>
    (la fonction affiche est appelée par le bouton validation d'un formulaire)

    http://w3.dtp.obs-mip.fr/RSSP/WEB_2..../sisRecent.php

  2. #2
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    16 959
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 16 959
    Points : 44 112
    Points
    44 112
    Par défaut
    Bonsoir,
    Citation Envoyé par Console d'erreur
    Erreur*: données incompréhensibles après l'élément de document
    Fichier Source*: http://w3.dtp.obs-mip.fr/RSSP/WEB_2.2/LaSismicite/txt2XML.php?annee=2010
    Ligne*: 2, Colonne*: 1
    Code Source*:
    <b>Warning</b>: fopen(): Unable to access ./data/sismi.10 in <b>/html/RSSP/WEB_2.2/LaSismicite/txt2XML.php</b> on line <b>14</b><br />
    Citation Envoyé par le Fichier généré
    <br />
    <b>Warning</b>: fopen(): Unable to access ./data/sismi.10 in <b>/html/RSSP/WEB_2.2/LaSismicite/txt2XML.php</b> on line <b>14</b><br />
    <br />
    <b>Warning</b>: fopen(./data/sismi.10): failed to open stream: No such file or directory in <b>/html/RSSP/WEB_2.2/LaSismicite/txt2XML.php</b> on line <b>14</b><br />
    <br />
    <b>Warning</b>: file(): Unable to access ./data/sismi.10 in <b>/html/RSSP/WEB_2.2/LaSismicite/txt2XML.php</b> on line <b>16</b><br />
    <br />
    <b>Warning</b>: file(./data/sismi.10): failed to open stream: No such file or directory in <b>/html/RSSP/WEB_2.2/LaSismicite/txt2XML.php</b> on line <b>16</b><br />
    <br />
    <b>Warning</b>: fclose(): supplied argument is not a valid stream resource in <b>/html/RSSP/WEB_2.2/LaSismicite/txt2XML.php</b> on line <b>17</b><br />
    <br />
    <b>Warning</b>: Invalid argument supplied for foreach() in <b>/html/RSSP/WEB_2.2/LaSismicite/txt2XML.php</b> on line <b>19</b><br />
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <markers>
    </markers>
    le fichier ne retourne donc aucun marker.

  3. #3
    Nouveau membre du Club
    Inscrit en
    Septembre 2005
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Septembre 2005
    Messages : 45
    Points : 27
    Points
    27
    Par défaut
    Merci de t'être penché sur mon problème.

    Cette erreur est due au fait qu'hier, après m'être déchiré les cheveux, j'ai tout repris de zéro.
    Cette fois, au lieu de générer un fichier KML, j'ai crée un fichier XML et utilisé les fonctions mis à disposition par util.js (http://code.google.com/p/gmaps-sampl...lparsing/?r=16).
    Quand tu as fait tes tests, mon fichier txt2XML.php ne fonctionnait pas encore : il manquait la ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    header("Content-Type: text/xml; charset=ISO-8859-1");
    Depuis, le problème a été résolu et, si je ne l'ais pas encore indiqué dans le titre du message, c'est qu'il était déjà tard quand la solution a été trouvée.

    Pour les personnes soumises au même problème :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
     
    ...
    <script type="text/javascript" src="util.js"></script>
    </head>
    (...)
    <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
    <script type="text/javascript">
    var myMap;
     
    window.onload = function () {
       var myLatlng = new google.maps.LatLng(42.7, 0.7);
       var myOptions = {
          zoom: 7,
          center: myLatlng,
          mapTypeId: google.maps.MapTypeId.TERRAIN
       }
       myMap = new google.maps.Map(
          document.getElementById('carte'),
          myOptions
          );
    }
     
    function affiche() {
       downloadUrl("./txt2XML.php?annee=" + annee, function(data) {
          var markers = data.documentElement.getElementsByTagName("marker");
          for (var i=0; i < markers.length; i++) {
             var latlng = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
             var marker = createMarker(markers[i].getAttribute("name"), latlng);
          }
       });
    }
     
    function createMarker(name, latlng) {
       var marker = new google.maps.Marker({position: latlng, map: myMap});
       return marker;
    }
    ...
    Pour voir le code au complet :
    http://w3.dtp.obs-mip.fr/RSSP/WEB_2..../sisRecent.php

    Avec le fichier txt2XML.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     
    <?php
    header("Content-Type: text/xml; charset=ISO-8859-1");
    //phpinfo();
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
     
    //$annee = "1998";
    $annee = $_GET["annee"];
    //$trim = $_GET["trim"];
    $ficXML = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
    $ficXML .= "<markers>\n";
     
    $aa = substr($annee, 2, 2);
    $f = fopen("./data/sismi.".$aa, "r");
    //$fichier = file ("./data/sismi.".$aa.$trim);
    $fichier = file ("./data/sismi.".$aa);
    fclose($f);
     
    foreach ($fichier as $ligne) {
       if (preg_match('`(\S+)\s+(\S+)\s+(\S+)\s+\S+\s+\S+\s+\S+\s+(\S+)\s+(\S+)\s+\S+\s+(\S+)`', $ligne, $dataSeisme)) {
          $ficXML .= "   <marker date=\"".sprintf("%02d%02d%02d", $dataSeisme[1], $dataSeisme[2], $dataSeisme[3])."\" lat=\"".$dataSeisme[4]."\" lng=\"".$dataSeisme[5]."\" mag=\"".$dataSeisme[6]."\" />\n";
       }
    }
     
    $ficXML .= "</markers>\n";
    echo $ficXML;
    ?>
    Désolé de t'avoir fait perdre ton temps et encore merci d'être penché sur mon problème.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XSLT] comment afficher toutes les données d'un fichier xml ?
    Par bwwilly dans le forum XSL/XSLT/XPATH
    Réponses: 19
    Dernier message: 27/06/2007, 16h21
  2. Comment afficher dans une page html un fichier flash sans problème d'activeX
    Par Alexandrebox dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 09/05/2007, 17h39
  3. [GD] comment afficher une image genérée par GD
    Par lochou dans le forum Bibliothèques et frameworks
    Réponses: 6
    Dernier message: 25/10/2006, 22h03
  4. Comment afficher 2 calques à la fois ?
    Par barracuda83 dans le forum Général JavaScript
    Réponses: 8
    Dernier message: 05/07/2006, 16h41
  5. Réponses: 1
    Dernier message: 15/11/2005, 15h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo