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

JavaScript Discussion :

google map api


Sujet :

JavaScript

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    1
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1
    Points : 2
    Points
    2
    Par défaut google map api
    bonjour
    voila mon probleme je veux afficher plusieur point sur une carte en fonctions des coordonnées (lat, lng)
    ces coordonnées sont dans une base de donnée mysql
    le probleme est que lorsque j'affiche ma carte j'obtient uniquement le dernier point de ma base de donnée alors que je voudrai que tout les point soit afficher

    voila mon code


    <!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>

    <?php
    mysql_connect("", "", "");
    mysql_select_db("");

    //on recupere la latitude longitude nom de la structure
    $reponse = mysql_query("SELECT Latitude,Longitude FROM T_Gps")

    while ($donnees = mysql_fetch_array($reponse)){


    ?>

    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>carte d'essai</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key="
    type="text/javascript"></script>
    <script type="text/javascript">

    //<![CDATA[
    function load() {
    if (GBrowserIsCompatible()) {

    function createMarker(point, number) {
    var marker = new GMarker(point,icon);
    GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowTabsHtml(infoTabs);
    });
    return marker;
    }
    var infoTabs = [
    new GInfoWindowTab(" info1", " "),
    new GInfoWindowTab(" info2", " ")
    ];

    //création d'une carte nommé "map"
    var map = new GMap2(document.getElementById("map"));
    GEvent.addListener(map, "moveend", function() {

    var center = map.getCenter();
    });

    map.addControl(new GSmallMapControl());

    map.addControl(new GMapTypeControl());


    map.setCenter(new GLatLng(45.44 , 4.395), Cool;


    var icon = new GIcon();

    icon.image = "http://images.google.fr/images?q=tbn:gS51abIJ6eysoM:http://rgfrance0.tripod.com/sitebuildercontent/sitebuilderpictures/flag.jpg";

    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";

    icon.iconSize = new GSize(23, 23);
    icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);



    var point = new GLatLng('<?php echo $donnees['Latitude']; ?>','<?php echo $donnees['Longitude'] ; ?>')
    map.addOverlay(createMarker(point ,1));
    marker.openInfoWindowTabsHtml(infoTabs);

    }
    }

    //]]>
    </script>
    <?php
    }
    mysql_close();
    ?>
    </head>
    <body onload="load()" onunload="GUnload()">
    <div id="map" style="width: 500px; height: 500px"></div>
    </body>
    </html>


    voila merci d'avance pour vos reponse

  2. #2
    Membre expérimenté
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    1 252
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2004
    Messages : 1 252
    Points : 1 419
    Points
    1 419
    Par défaut
    Bon, primo, va falloir regrouper tout ton PHP en un seul endroit. Tu verras, ça ira dix fois mieux.

    Ensuite, j'ai refait ton code. J'ai pas tout compris alors, j'ai tout indenté correctement, mis le PHP en début de code et appelé les variables PHP lorsque c'était nécessaire.

    Ton problème était que tu appelais une fois le JavaScript par tuple dans ta base de données. Alors, bien évidemment, un seul load était appelé, et pas les X que tu tentes d'instancier.

    Sinon, je n'ai pas testé le code, mais à priori, il devrait être bon. Si tu as davantages de problèmes, continue le post ci-dessous

    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    <?php
     
    mysql_connect("", "", "");
    mysql_select_db("");
     
    $reponse = mysql_query("SELECT Latitude,Longitude FROM T_Gps")
     
    $data = array();
     
    while ($donnees = mysql_fetch_array($reponse)){
      $data[] = $donnees;
    }
     
    mysql_close();
     
    ?>
    <!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>carte d&apos;essai</title>
        <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=" type="text/javascript"></script>
        <script type="text/javascript">
          //<![CDATA[
          function load() {
            if (GBrowserIsCompatible()) {
              function createMarker(point, number) {
                var marker = new GMarker(point,icon);
                GEvent.addListener(marker, "click", function() {
                    marker.openInfoWindowTabsHtml(infoTabs);
                  });
                return marker;
              }
              var infoTabs = [
                  new GInfoWindowTab(" info1", " "),
                  new GInfoWindowTab(" info2", " ")
                ];
     
              //création d'une carte nommé "map"
              var map = new GMap2(document.getElementById("map"));
              GEvent.addListener(map, "moveend", function() {
                  var center = map.getCenter();
                });
     
              map.addControl(new GSmallMapControl());
              map.addControl(new GMapTypeControl());
              map.setCenter(new GLatLng(45.44 , 4.395), Cool;
     
              var icon = new GIcon();
              icon.image = "http://images.google.fr/images?q=tbn:gS51abIJ6eysoM:http://rgfrance0.tripod.com/sitebuildercontent/sitebuilderpictures/flag.jpg";
              icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
              icon.iconSize = new GSize(23, 23);
              icon.shadowSize = new GSize(22, 20);
              icon.iconAnchor = new GPoint(6, 20);
              icon.infoWindowAnchor = new GPoint(5, 1);
     
    <?php foreach ($data as $donnees): ?>
              var point = new GLatLng('<?php echo $donnees['Latitude']; ?>','<?php echo $donnees['Longitude'] ; ?>')
              map.addOverlay(createMarker(point ,1));
    <?php endforeach;  ?>
     
              marker.openInfoWindowTabsHtml(infoTabs);
            } // fin if (GBrowserIsCompatible())
          } // fin load()
          //]]>
        </script>
      </head>
      <body onload="load()" onunload="GUnload()">
        <div id="map" style="width: 500px; height: 500px"></div>
      </body>
    </html>
    P.S. Je ne sais pas du tout ce que fait la dernière ligne JavaScript, mais à priori, elle ne fait rien et risque de te poser problème.

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

Discussions similaires

  1. Google map API
    Par rudylar dans le forum Général JavaScript
    Réponses: 0
    Dernier message: 02/07/2008, 18h53
  2. google map api
    Par debutantasp dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 30/05/2008, 14h02
  3. Google Map - API Java ?
    Par onlytoine dans le forum Collection et Stream
    Réponses: 3
    Dernier message: 28/04/2008, 11h25
  4. Utilisation de la Google Maps API ?
    Par [ZiP] dans le forum Web & réseau
    Réponses: 4
    Dernier message: 04/09/2007, 22h26
  5. Google Map API --> Javascript et code behind C#
    Par bridel dans le forum ASP.NET
    Réponses: 2
    Dernier message: 22/01/2007, 21h07

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