Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
928 connectés 

  FORUM HardWare.fr
  Programmation
  PHP

  pb API google map et bdd php/sql

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

pb API google map et bdd php/sql

n°1755452
Antho03
Posté le 04-07-2008 à 10:15:45  profilanswer
 

Bonjour à tous,
 
Je souhaite intégrer dans mon site un affichage de résultats d'un formulaire dans l'api google map. Voilà mon code :
 

Code :
  1. <?php
  2.          mysql_connect("", "", "" );
  3.           mysql_select_db("" );
  4.  
  5.     //on recupere la latitude longitude nom de la structure     
  6.           $reponse = mysql_query("SELECT Latitude,Longitude FROM T_Gps" )
  7.     ?>
  8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  9.   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  10. <html xmlns="http://www.w3.org/1999/xhtml">
  11.   <head>
  12.     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  13.     <title>carte d'essai</title>
  14.     <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key="
  15.       type="text/javascript"></script>
  16.     <script type="text/javascript">
  17.     //<![CDATA[
  18.      function load() {
  19.       if (GBrowserIsCompatible()) {
  20.        
  21.           function createMarker(point, number) {
  22.                   var marker = new GMarker(point,icon);
  23.                   GEvent.addListener(marker, "click", function() {
  24.                   marker.openInfoWindowTabsHtml(infoTabs);           
  25.                   });
  26.                    return marker;
  27.             }
  28.             var infoTabs = [
  29.              new GInfoWindowTab("  info1", "  " ),
  30.               new GInfoWindowTab(" info2", "  " )
  31.             ];
  32.      //création d'une carte nommé "map"
  33.             var map = new GMap2(document.getElementById("map" ));
  34.                         GEvent.addListener(map, "moveend", function() {
  35.      
  36.             var center = map.getCenter();
  37.                 });
  38.      
  39.             map.addControl(new GSmallMapControl());
  40.        
  41.             map.addControl(new GMapTypeControl());
  42.      
  43.          
  44.             map.setCenter(new GLatLng(45.44 , 4.395), 8);
  45.                
  46.          
  47.             var icon = new GIcon();
  48.      
  49.             icon.image = "http://images.google.fr/images?q=tbn:gS51abIJ6eysoM:http://rgfrance0.tripod.com/sitebuildercontent/sitebuilderpictures/flag.jpg";
  50.      
  51.             icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
  52.    
  53.             icon.iconSize = new GSize(23, 23);
  54.             icon.shadowSize = new GSize(22, 20);
  55.             icon.iconAnchor = new GPoint(6, 20);
  56.             icon.infoWindowAnchor = new GPoint(5, 1);           
  57.              
  58.            
  59.         <?php while ($donnees = mysql_fetch_array($reponse)){?>
  60.             var point = new GLatLng('<?php echo $donnees['Latitude']; ?>','<?php echo $donnees['Longitude'] ; ?>')
  61.              map.addOverlay(createMarker(point ,1));
  62.              marker.openInfoWindowTabsHtml(infoTabs);
  63.          
  64.       }
  65.     }
  66.  
  67. </script>
  68. <?php
  69. mysql_close()    ;
  70.        }
  71.     ?> 
  72.   </head>
  73.   <body onload="load()" onunload="GUnload()">
  74.     <div id="map" style="width: 500px; height: 500px"></div>
  75.   </body>
  76. </html>


 
Il fonctionne correctement avec un seul enregistrement dans la table mais pas avec plusieurs. Il affiche seulement la première donnée de la table (marqueur sur la carte) et n'arrive pas à créer et afficher d'autres marqueurs (correspondants aux autres données).
 
message d'erreur :
 
"var point = new GLatLng('43.672031','1.448878') map.addOverlay(createMarker(point ,1)); marker.openInfoWindowTabsHtml(infoTabs); } } "
 
Au premier passage de la boucle, les instructions sont exécutées correctement, par contre dès le seconde passage le script JS de la boucle est affiché à l'écran et non interprété/
 
D'où peux venir le soucis ?
 
Merci d'avance pour votre aide.

mood
Publicité
Posté le 04-07-2008 à 10:15:45  profilanswer
 

n°1755477
ouiouioui1​0
ChuckNorris sait diviser par 0
Posté le 04-07-2008 à 10:38:49  profilanswer
 

juste vite fait je connais pas google map, mais si tu incremente le 1 ?
(point ,1)
en
(point ,<?php echo $i $i++; ?> )

 

met $i = 1; avant ton while


Message édité par ouiouioui10 le 04-07-2008 à 10:39:56
n°1755522
Antho03
Posté le 04-07-2008 à 11:42:51  profilanswer
 

merci, mais ça ne change rien.
 
La boucle ne s'exécute toujours qu'une seule fois, je ne comprend pas pourquoi  :(

n°1755523
cvb
Posté le 04-07-2008 à 11:43:21  profilanswer
 

Est-ce que tu es sure que la boucle ramène tout les enregistrements ?

n°1755531
Antho03
Posté le 04-07-2008 à 11:51:43  profilanswer
 

Oui, car quand je fais un test d'affichage des latitudes, par exemple :
 
include("connect.php" );  
   
if ($_POST[type] == 'maison')    
   $reponse = mysql_query("SELECT latitude,longitude FROM maison WHERE departement='$departement'" );  
   
if ($_POST[type] == 'appartement')    
   $reponse = mysql_query("SELECT latitude,longitude FROM appartement WHERE departement='$departement'" );  
 
while ($donnees = mysql_fetch_array($reponse))
{
 echo  $donnees['latitude'];
}
 
les latitudes s'affichent toutes bien.

n°1755536
cvb
Posté le 04-07-2008 à 11:59:45  profilanswer
 

Il manque des paramètres dans ton CreateMarker...
Scince les deux également.
 
Regarde dans le code source du site : http://audit.fondev.org (J'ai utilise Google Maps)
 

Code :
  1. var _infoTabs = [
  2. new GInfoWindowTab("Information General", "<table width='400px' border='0' cellspacing='1'><tr><td  class='info_bulle_google_label'>&nbsp;&nbsp;Nom Fonera&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Lattitude&nbsp;&nbsp;</td><td  class='info_bulle_google_label'&nbsp;&nbsp;>Longitude&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Poles&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Meridien&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Altitude&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Satellite&nbsp;&nbsp;</td></tr><tr><td class='info_bulle_google_info'>FON_GRATUIT_HUIT_ET_DEMI</td><td class='info_bulle_google_info'>44.910349</td><td class='info_bulle_google_info'>-0.633207</td><td class='info_bulle_google_info'>N</td><td class='info_bulle_google_info'>W</td><td class='info_bulle_google_info'>16.80</td><td class='info_bulle_google_info'>7</td></tr></table>" ),
  3. new GInfoWindowTab("HTTP", "<table width='400px' border='0' cellspacing='1'><tr><td  class='info_bulle_google_label'>&nbsp;&nbsp;Date D&eacute;but&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Date fin&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Minimum&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Maximum&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Moyenne&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;URL&nbsp;&nbsp;</td></tr><tr><td class='info_bulle_google_info'>&nbsp;&nbsp;2008-04-15 18:32:05&nbsp;&nbsp;</td><td class='info_bulle_google_info'>&nbsp;&nbsp;2008-04-15 18:32:30&nbsp;&nbsp;</td><td class='info_bulle_google_info'>&nbsp;&nbsp;22.43&nbsp;&nbsp;</td><td class='info_bulle_google_info'>&nbsp;&nbsp;92.86&nbsp;&nbsp;</td><td class='info_bulle_google_info'>&nbsp;&nbsp;50.95&nbsp;&nbsp;</td><td class='info_bulle_google_info'>&nbsp;&nbsp;http://www.rarlab.com/rar/wrar371fr.exe&nbsp;&nbsp;</td></tr></table>" ),
  4. new GInfoWindowTab("FTP", "<table width='400px' border='0' cellspacing='1'><tr><td  class='info_bulle_google_label'>&nbsp;&nbsp;Date D&eacute;but&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Date fin&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Minimum&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Maximum&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Moyenne&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;URL&nbsp;&nbsp;</td></tr><tr><td class='info_bulle_google_info'>&nbsp;&nbsp;2008-04-15 18:32:31&nbsp;&nbsp;</td><td class='info_bulle_google_info'>&nbsp;&nbsp;2008-04-15 18:36:36&nbsp;&nbsp;</td><td class='info_bulle_google_info'>&nbsp;&nbsp;NC&nbsp;&nbsp;</td><td class='info_bulle_google_info'>&nbsp;&nbsp;NC&nbsp;&nbsp;</td><td class='info_bulle_google_info'>&nbsp;&nbsp;1.50&nbsp;&nbsp;</td><td class='info_bulle_google_info'>&nbsp;&nbsp;ftp.demo1g.ovh.org&nbsp;&nbsp;</td></tr></table>" )
  5. ];
  6. var _marker = new createMarker(_point,_icon,_infoTabs);
  7. _map.addOverlay(_marker);

n°1755541
Antho03
Posté le 04-07-2008 à 12:08:35  profilanswer
 

Pourtant lors du premier passage tout s'affiche correctement sur la map, les points, les info-bulles etc...
 
ça vient d'un problème sur le While mais je ne vois pas ou ?

n°1755546
cvb
Posté le 04-07-2008 à 12:13:21  profilanswer
 

Non, ca vient du code Google Maps, un objet est crée pour chaque point...Dans ton code ce n'est pas le cas !!!  
Ca explique pourquoi il ne te crée pas les autres points....
 

Code :
  1. map.addOverlay(createMarker(point ,1));
  2. marker.openInfoWindowTabsHtml(infoTabs);


Message édité par cvb le 04-07-2008 à 12:14:03
n°1755552
Antho03
Posté le 04-07-2008 à 12:17:37  profilanswer
 

D'accord, et donc comment faut-il que je fasse, par rapport à mon code, pour que plusieurs points soient créés ?

n°1755563
cvb
Posté le 04-07-2008 à 12:25:25  profilanswer
 

Est-ce que tu as regarde ce que je t'ai mis plus haut ?  
Scinde les fonctions en deux, et inspire toi de mon code...
 
==> Ton code :

Code :
  1. (...)
  2. map.addOverlay(createMarker(point ,1));
  3. marker.openInfoWindowTabsHtml(infoTabs);
  4. (...)


 
 
 
==> Mon code :
 

Code :
  1. (...)
  2. var _infoTabs = [
  3. new GInfoWindowTab("Information General", "<table width='400px' border='0' cellspacing='1'><tr><td  class='info_bulle_google_label'>&nbsp;&nbsp;Nom Fonera&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Lattitude&nbsp;&nbsp;</td><td  class='info_bulle_google_label'&nbsp;&nbsp;>Longitude&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Poles&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Meridien&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Altitude&nbsp;&nbsp;</td><td  class='info_bulle_google_label'>&nbsp;&nbsp;Satellite&nbsp;&nbsp;</td></tr><tr><td class='info_bulle_google_info'>FON_GRATUIT_HUIT_ET_DEMI</td><td class='info_bulle_google_info'>44.910349</td><td class='info_bulle_google_info'>-0.633207</td><td class='info_bulle_google_info'>N</td><td class='info_bulle_google_info'>W</td><td class='info_bulle_google_info'>16.80</td><td class='info_bulle_google_info'>7</td></tr></table>" )
  4. var _marker = new createMarker(_point,_icon,_infoTabs);
  5. _map.addOverlay(_marker);
  6. (...)


Message édité par cvb le 04-07-2008 à 12:26:02
mood
Publicité
Posté le 04-07-2008 à 12:25:25  profilanswer
 

n°1755567
Antho03
Posté le 04-07-2008 à 12:43:49  profilanswer
 

Nikel, t'es un chef, ça marche !!
 
Par contre, tant que tu es la, j'en profite :
 
tout marche nikel sous FF, par contre sous IE, la map s'affiche mais pas les markers.
Saurais tu pourquoi ?

n°1755596
cvb
Posté le 04-07-2008 à 14:01:31  profilanswer
 

De rien avec plaisir.
 
Je trouve ça curieux que ça fonctionne sous FF et pas sous IE, c'est l'inverse qui se produit en général ? T'es sûre à 100% ?  
 
J'ai eue des soucis comme ça aussi mais c'était due à des erreurs de code, oublie de ID. Contrairement à toi ça fonctionné sous IE mais pas FF.
 
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  PHP

  pb API google map et bdd php/sql

 

Sujets relatifs
Google ChartsBesoin d'aide sur l'API de microsoft RTC
Format et précision d'un float (google n'est pas mon amis). DebutantSoap google search api
Récupération données Google AnalyticsIndexation Google
Que faire quand un site disparaît des résultats Google?gadget google
Tracer des zones [ API Google ]API Google en Java
Plus de sujets relatifs à : pb API google map et bdd php/sql


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR