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 :

Affichage des marqueurs sur une carte à partir d'une base de donnée [Google Maps]


Sujet :

APIs Google

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Femme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2012
    Messages : 22
    Par défaut Affichage des marqueurs sur une carte à partir d'une base de donnée
    Bonjour,

    J'essaie d'afficher des marqueurs sur une carte à partir d'une base de données.
    J'ai suivi le tutoriel suivant: http://tips4php.net/2010/10/use-php-...g-data-on-map/ et je l'ai adapté à ma base de données.
    Le problème c'est que je ne vois pas de marqueur quand j'exécute ce code.

    Ci-joint le code, la table mysql s'appelle appreciation et contient une colonne latitudes et une autre colonne longitude et un colonne idAppreciation :

    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    <?
                 $dbname            ='survey'; //Name of the database
                 $dbuser            ='root'; //Username for the db
                 $dbpass            =''; //Password for the db
                 $dbserver          ='localhost'; //Name of the mysql server
     
                 $dbcnx = mysql_connect ("$dbserver", "$dbuser", "$dbpass");
                 mysql_select_db("$dbname") or die(mysql_error());
              ?>
              <?
                $query = mysql_query("SELECT * FROM appreciation");
                while ($row = mysql_fetch_array($query)){
                $name=$row['idAppreciation'];
                $lat=$row['latitude'];
                $lon=$row['longitude'];
                $desc=$row['zone'];
                echo ("addMarker($lat, $lon,'<b>$name</b><br/>$desc');\n");
                }
                ?>
               <html>
               <head>
                <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
               <title>Google Map API V3 with markers</title>
              <style type="text/css">
               body { font: normal 10pt Helvetica, Arial; }
              #map { width: 350px; height: 300px; border: 0px; padding: 0px; }
               </style>
              <script src="http://maps.google.com/maps/api/js?v=3&sensor=false"                  type="text/javascript"></script>
                <script type="text/javascript">
     //Sample code written by August Li
     var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
     new google.maps.Size(32, 32), new google.maps.Point(0, 0),
     new google.maps.Point(16, 32));
     var center = null;
     var map = null;
     var currentPopup;
     var bounds = new google.maps.LatLngBounds();
     function addMarker(lat, lng, info) {
     var pt = new google.maps.LatLng(lat, lng);
     bounds.extend(pt);
     var marker = new google.maps.Marker({
     position: pt,
     icon: icon,
     map: map
     });
     var popup = new google.maps.InfoWindow({
     content: info,
     maxWidth: 300
     });
     google.maps.event.addListener(marker, "click", function() {
     if (currentPopup != null) {
     currentPopup.close();
     currentPopup = null;
     }
     popup.open(map, marker);
     currentPopup = popup;
     });
     google.maps.event.addListener(popup, "closeclick", function() {
     map.panTo(center);
     currentPopup = null;
     });
     }
     function initMap() {
     map = new google.maps.Map(document.getElementById("map"), {
     center: new google.maps.LatLng(0, 0),
     zoom: 14,
     mapTypeId: google.maps.MapTypeId.ROADMAP,
     mapTypeControl: false,
     mapTypeControlOptions: {
     style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
     },
     navigationControl: true,
     navigationControlOptions: {
     style: google.maps.NavigationControlStyle.SMALL
     }
     });
     
     center = bounds.getCenter();
     map.fitBounds(bounds);
     
     }
     </script>
     </head>
     <body onload="initMap()" style="margin:0px; border:0px; padding:0px;">
     <div id="map"></div>
     </html>

  2. #2
    Membre actif
    Inscrit en
    Août 2008
    Messages
    47
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Août 2008
    Messages : 47
    Par défaut
    Bonjour,

    c'est parce que tu fais appel à la fonction
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    echo ("addMarker($lat, $lon,'<b>$name</b><br/>$desc');\n");
    Avant qu'elle soit créée, déplace ce code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
              <?
                $query = mysql_query("SELECT * FROM appreciation");
                while ($row = mysql_fetch_array($query)){
                $name=$row['idAppreciation'];
                $lat=$row['latitude'];
                $lon=$row['longitude'];
                $desc=$row['zone'];
                echo ("addMarker($lat, $lon,'<b>$name</b><br/>$desc');\n");
                }
                ?>
    juste avant la balise </script>

  3. #3
    Membre averti
    Femme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2012
    Messages : 22
    Par défaut
    Merci beaucoup pour ta réponse. Cependant quand le code devient :

    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    <?
    $dbname            ='survey'; //Name of the database
    $dbuser            ='root'; //Username for the db
    $dbpass            =''; //Password for the db
    $dbserver          ='localhost'; //Name of the mysql server
     
    $dbcnx = mysql_connect ("$dbserver", "$dbuser", "$dbpass");
    mysql_select_db("$dbname") or die(mysql_error());
    ?>
     
    <html>
     <head>
     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
     <title>Google Map API V3 with markers</title>
     <style type="text/css">
     body { font: normal 10pt Helvetica, Arial; }
     #map { width: 350px; height: 300px; border: 0px; padding: 0px; }
     </style>
     <script src="http://maps.google.com/maps/api/js?v=3&sensor=false" type="text/javascript"></script>
     <script type="text/javascript">
     //Sample code written by August Li
     var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
        new google.maps.Size(32, 32), new google.maps.Point(0, 0),
        new google.maps.Point(16, 32));
     var center = null;
     var map = null;
     var currentPopup;
     var bounds = new google.maps.LatLngBounds();
     function addMarker(lat, lng, info) {
        var pt = new google.maps.LatLng(lat, lng);
        bounds.extend(pt);
        var marker = new google.maps.Marker({
           position: pt,
           icon: icon,
           map: map
        });
        var popup = new google.maps.InfoWindow({
           content: info,
           maxWidth: 300
        });
        google.maps.event.addListener(marker, "click", function() {
           if (currentPopup != null) {
              currentPopup.close();
              currentPopup = null;
           }
           popup.open(map, marker);
           currentPopup = popup;
        });
        google.maps.event.addListener(popup, "closeclick", function() {
           map.panTo(center);
           currentPopup = null;
        });
     }
     function initMap() {
        map = new google.maps.Map(document.getElementById("map"), {
           center: new google.maps.LatLng(0, 0),
           zoom: 14,
           mapTypeId: google.maps.MapTypeId.ROADMAP,
           mapTypeControl: false,
           mapTypeControlOptions: {
              style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
           },
           navigationControl: true,
           navigationControlOptions: {
              style: google.maps.NavigationControlStyle.SMALL
           }
        });
     
        center = bounds.getCenter();
        map.fitBounds(bounds);
     
     }
     <?php
                     $query = mysql_query("SELECT * FROM appreciation");
                     while ($row = mysql_fetch_array($query)){
                     $name=$row['idAppreciation'];
                     $lat=$row['latitude'];
                     $lon=$row['longitude'];
                     $desc=$row['zone'];
                     echo ("addMarker($lat, $lon,'<b>$name</b><br/>$desc');\n");
                     }
                     ?>
     </script>
     </head>
     <body onload="initMap()" style="margin:0px; border:0px; padding:0px;">
     <div id="map"></div>
     </html>

    J'espère que c'est la correction que vous avez proposé, je ne vois plus rien sur la carte et quand j'inspecte l'élément avec google chrome je reçois les erreurs suivantes :

    Uncaught SyntaxError: Unexpected token <
    Uncaught ReferenceError: initMap is not defined
    Merci pour votre aide, j'en ai vraiment besoin.

  4. #4
    Membre actif
    Inscrit en
    Août 2008
    Messages
    47
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Août 2008
    Messages : 47
    Par défaut
    oups, fallait plutot le mettre ici
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    <?php
    $query = mysql_query("SELECT * FROM appreciation");
    while ($row = mysql_fetch_array($query)){
    $name=$row['idAppreciation'];
    $lat=$row['latitude'];
    $lon=$row['longitude'];
    $desc=$row['zone'];
    echo "addMarker($lat, $lon,'<b>$name</b><br/>$desc');";
    }
    ?>
     
    center = bounds.getCenter();
    map.fitBounds(bounds);

  5. #5
    Membre averti
    Femme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2012
    Messages : 22
    Par défaut
    Le problème persiste. Plus de carte et les deux erreurs quand j'inspecte l'élément dans google chrome :

    #
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Uncaught SyntaxError: Unexpected token <                  test3.jsp:68
    Uncaught ReferenceError: initMap is not defined             test3.jsp:86
    onload

  6. #6
    Membre actif
    Inscrit en
    Août 2008
    Messages
    47
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Août 2008
    Messages : 47
    Par défaut
    je vois que t'es en jsp, ça marche php avec jsp ?

  7. #7
    Membre averti
    Femme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2012
    Messages : 22
    Par défaut
    oui ça marche

  8. #8
    Membre actif
    Inscrit en
    Août 2008
    Messages
    47
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Août 2008
    Messages : 47
    Par défaut
    Essais avec ça, sans rien modifier

    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
     
     
    <html>
        <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
            <title>Google Map API V3 with markers</title>
            <style type="text/css">
                body { font: normal 10pt Helvetica, Arial; }
                #map { width: 350px; height: 300px; border: 0px; padding: 0px; }
            </style>
            <script src="http://maps.google.com/maps/api/js?v=3&sensor=false" type="text/javascript"></script>
            <script type="text/javascript">
                //Sample code written by August Li
                var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
                           new google.maps.Size(32, 32), new google.maps.Point(0, 0),
                           new google.maps.Point(16, 32));
                var center = null;
                var map = null;
                var currentPopup;
                var bounds = new google.maps.LatLngBounds();
                function addMarker(lat, lng, info) {
                    var pt = new google.maps.LatLng(lat, lng);
                    bounds.extend(pt);
                    var marker = new google.maps.Marker({
                        position: pt,
                        icon: icon,
                        map: map
                    });
                    var popup = new google.maps.InfoWindow({
                        content: info,
                        maxWidth: 300
                    });
                    google.maps.event.addListener(marker, "click", function() {
                        if (currentPopup != null) {
                            currentPopup.close();
                            currentPopup = null;
                        }
                        popup.open(map, marker);
                        currentPopup = popup;
                    });
                    google.maps.event.addListener(popup, "closeclick", function() {
                        map.panTo(center);
                        currentPopup = null;
                    });
                }
                function initMap() {
                    map = new google.maps.Map(document.getElementById("map"), {
                        center: new google.maps.LatLng(0, 0),
                        zoom: 14,
                        mapTypeId: google.maps.MapTypeId.ROADMAP,
                        mapTypeControl: false,
                        mapTypeControlOptions: {
                        style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
                        },
                        navigationControl: true,
                        navigationControlOptions: {
                         style: google.maps.NavigationControlStyle.SMALL
                        }
                    });
                    <?php // loading makers from database	
    		            $dbname            ='survey'; //Name of the database
    		            $dbuser            ='root'; //Username for the db
    		            $dbpass            =''; //Password for the db
    		            $dbserver          ='localhost'; //Name of the mysql server
     
    		            $dbcnx = mysql_connect ("$dbserver", "$dbuser", "$dbpass");
    		            mysql_select_db($dbname) or die(mysql_error());
     
    		            $query = mysql_query("SELECT * FROM appreciation");
    		            while ($row = mysql_fetch_array($query))
    		            {
    			            $name=$row['idAppreciation'];
    			            $lat=$row['latitude'];
    			            $lon=$row['longitude'];
    			            $desc=$row['zone'];
    			            echo "addMarker($lat, $lon,'<b>$name</b><br/>$desc');";
    			        }
    		        ?>    	
    	                /*
    	                addMarker(51.514980, -0.144328,'<b>100 Club</b><br/>Oxford Street, London  W1&lt;br/&gt;3 Nov 2010 : Buster Shuffle&lt;br/&gt;');
    					addMarker(51.521710, -0.071737,'<b>93 Feet East</b><br/>150 Brick Lane, London  E1 6RU&lt;br/&gt;7 Dec 2010 : Jenny &amp; Johnny&lt;br/&gt;');
    					addMarker(51.511010, -0.120140,'<b>Adelphi Theatre</b><br/>The Strand, London  WC2E 7NA&lt;br/&gt;11 Oct 2010 : Love Never Dies');
    					addMarker(51.521620, -0.143394,'<b>Albany, The</b><br/>240 Gt. Portland Street, London  W1W 5QU');
    					addMarker(51.513170, -0.117503,'<b>Aldwych Theatre</b><br/>Aldwych, London  WC2B 4DF&lt;br/&gt;11 Oct 2010 : Dirty Dancing');
    					addMarker(51.596490, -0.109514,'<b>Alexandra Palace</b><br/>Wood Green, London  N22&lt;br/&gt;30 Oct 2010 : Lynx All-Nighter');
    					*/
                    	center = bounds.getCenter();
                    	map.fitBounds(bounds);
     
                }
            </script>
        </head>
        <body onload="initMap()" style="margin:0px; border:0px; padding:0px;">
            <div id="map"></div>
    		<br/>
    		<br/>
    		<a href="http://tips4php.net/2010/10/use-php-mysql-and-google-map-api-v3-for-displaying-data-on-map/">Back to Use PHP and Mysql for displaying data on Google maps</a>
    </body>
    </html>

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

Discussions similaires

  1. Afficher une carte à partir d'une adresse
    Par okoweb dans le forum APIs Google
    Réponses: 4
    Dernier message: 28/05/2014, 19h30
  2. Réponses: 1
    Dernier message: 10/04/2012, 09h28
  3. [MySQL] Afficher une image à partir stockée en base de données
    Par arti2004 dans le forum PHP & Base de données
    Réponses: 22
    Dernier message: 21/06/2011, 19h40
  4. Réponses: 2
    Dernier message: 16/01/2008, 18h40
  5. [MySQL] Afficher une photo à partir de la base de données
    Par microcongo dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 07/09/2005, 17h29

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