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

  FORUM HardWare.fr
  Programmation
  PHP

  Google Map

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Google Map

n°1847004
marquito
Posté le 04-02-2009 à 10:43:39  profilanswer
 

Bonjour, comme j'ai toujours été bien aidé sur ce forum je reviens vous voir sur un sujet concernant les cartes de Google.
J'ai un script qui affiche la carte quand je renseigne la ville, le code postal et l'adresse jusqu'à là c'est tout bon :bounce: Si je ne renseigne pas l'adresse rien ne s'affiche  :pfff:  
Mais moi j'aimerai pouvoir montrer la la carte même si l'adresse n'ai pas renseignée !
Vous voyez le truc il arrive que certain utilisateur n'on pas d'adresse par exemple les entreprise dans les zones.
Je vous montre le code et je vous remercie pour votre aide  :sol:  

Code :
  1. <?php
  2. class GoogleMap
  3. {
  4.     private $apiKey;
  5.     private $points = array();
  6.     private $tags;
  7.     private $depth;
  8.     private $xmlArray;
  9.     private $zoomLevel;
  10.     private $showControl = true;
  11.     private $controlType = "small";
  12.     private $showMapType = true;
  13.     private $responseCode;
  14.    
  15.     public function setApiKey($apiKey)
  16.     {
  17.         $this->apiKey = $apiKey;
  18.     }
  19.    
  20.     public function setZoomLevel($zoomLevel)
  21.     {
  22.         $this->zoomLevel = $zoomLevel;
  23.     }
  24.    
  25.     public function addGeoPoint($lat, $lng, $description = "" )
  26.     {
  27.         $point = array("lat" => $lat,
  28.                        "lng" => $lng,
  29.                        "address" => "",
  30.                        "description" => $description);
  31.        
  32.         array_push($this->points, $point);
  33.     }
  34.    
  35.     public function addAddress($address, $description = "" )
  36.     {
  37.         $url = "http://maps.google.com/maps/geo?&output=xml&key=".$this->apiKey."&q=".urlencode($address);
  38.         $buff = @file_get_contents($url);
  39.         $results = $this->xml2array(utf8_encode($buff));
  40.        
  41.         $this->responseCode = (!empty($results['kml']['Response']['Status']['code'])) ? $results['kml']['Response']['Status']['code'] : 0;
  42.        
  43.         if(!empty($results['kml']['Response']['Placemark']['Point']['coordinates']))
  44.         {
  45.             $coords = explode(",", $results['kml']['Response']['Placemark']['Point']['coordinates']);
  46.            
  47.             $point = array("lat" => $coords[1],
  48.                            "lng" => $coords[0],
  49.                            "address" => $address,
  50.                            "description" => $description);
  51.            
  52.             array_push($this->points, $point);
  53.             return array("lat" => $coords[1], "lng" => $coords[0]);
  54.         }
  55.        
  56.         return false;
  57.     }
  58.    
  59.     public function validPointsExists()
  60.     {
  61.         return (!empty($this->points));
  62.     }
  63.    
  64.     public function isServiceProblem()
  65.     {
  66.         return ($this->responseCode != 200);
  67.     }
  68.    
  69.     public function getScriptCode()
  70.     {
  71.         return "\n<script src=\"http://maps.google.com/maps?file=api&amp;v=2&amp;key=".$this->apiKey."\" type=\"text/javascript\"></script>\n";
  72.     }
  73.    
  74.     public function getMapCode()
  75.     {
  76.         $html = "<script type=\"text/javascript\">\n
  77.         function showGoogleMap()
  78.         {
  79.         //<![CDATA[
  80.         if (GBrowserIsCompatible())
  81.         {
  82.         var map = new GMap(document.getElementById(\"map\" ));
  83.         map.centerAndZoom(new GLatLng(".$this->points[0]['lat'].",".$this->points[0]['lng']." ), ".$this->zoomLevel." );
  84.         }
  85.         var icon = new GIcon();
  86.         icon.image = \"http://labs.google.com/ridefinder/images/mm_20_red.png\";
  87.         icon.shadow = \"http://labs.google.com/ridefinder/images/mm_20_shadow.png\";
  88.         icon.iconSize = new GSize(12, 20);
  89.         icon.shadowSize = new GSize(22, 20);
  90.         icon.iconAnchor = new GPoint(6, 20);
  91.         icon.infoWindowAnchor = new GPoint(5, 1);
  92.         ";
  93.        
  94.         if($this->showControl)
  95.         {
  96.             switch($this->controlType)
  97.             {
  98.                 case "small": $html .= "map.addControl(new GSmallMapControl());\n"; break;
  99.                 case "large": $html .= "map.addControl(new GLargeMapControl());\n"; break;
  100.             }
  101.         }
  102.        
  103.         if($this->showMapType)
  104.         {
  105.             $html .= "map.addControl(new GMapTypeControl());\n";
  106.         }
  107.        
  108.         $i = 0;
  109.        
  110.         foreach($this->points as $point)
  111.         {
  112.             $i++;
  113.            
  114.             $html .= "
  115.             var point".$i." = new GLatLng(".$point['lat'].",".$point['lng']." );
  116.             var marker".$i." = new GMarker(point".$i." );
  117.             map.addOverlay(marker".$i." );
  118.             ";
  119.                
  120.             $infoText = ($point['description']) ? $point['description'] : htmlspecialchars($point['address']);
  121.            
  122.             if($infoText)
  123.             {
  124.                 $html .= "GEvent.addListener(marker".$i.", \"click\", function(){
  125.                 marker".$i.".openInfoWindowHtml(\"".$infoText."\" );
  126.                 });
  127.                 ";
  128.             }           
  129.         }
  130.        
  131.         $html .= "//]]>
  132.         }
  133.         \$(window).addEvent(\"load\", showGoogleMap);
  134.         </script>
  135.         ";
  136.        
  137.         return $html;
  138.     }
  139.    
  140.     public function getUserSideMapCode($address, $description = "" )
  141.     {
  142.         $point = array(
  143.                            "address" => $address,
  144.                            "description" => $description);
  145.            
  146.         array_push($this->points, $point);
  147.            
  148.         $html = "<script type=\"text/javascript\">\n
  149.         function showGoogleMap()
  150.         {
  151.             var map = new GMap(document.getElementById(\"map\" ));
  152.             map.enableContinuousZoom();
  153.             map.enableInfoWindow();
  154.             map.addControl(new GSmallMapControl());
  155.             map.addControl(new GMapTypeControl());
  156.             //map.addControl(new GOverviewMapControl());
  157.            
  158.             var geo = new GClientGeocoder();
  159.         ";
  160.        
  161.         $i = 0;
  162.        
  163.         foreach($this->points as $point)
  164.         {
  165.             $i++;
  166.            
  167.             $html .= "geo.getLocations('".addslashes($point['address'])."', function(result)
  168.             {
  169.                 if(result.Status.code != G_GEO_SUCCESS)
  170.                 {
  171.                     alert(result.Status.code);
  172.                     return;
  173.                 }
  174.                
  175.                 map.clearOverlays();
  176.                
  177.                 var p = result.Placemark[0].Point.coordinates;
  178.                 var lng = p[1];
  179.                 var lat = p[0];
  180.                
  181.                 var latLng = new GLatLng(parseFloat(lng), parseFloat(lat));
  182.                 map.centerAndZoom(latLng, ".($this->zoomLevel)." );
  183.                 var marker".$i." = new GMarker(latLng);
  184.                 map.addOverlay(marker".$i." );
  185.                 ";
  186.                
  187.                 $infoText = ($point['description']) ? $point['description'] : htmlspecialchars($point['address']);
  188.                
  189.                 if($infoText)
  190.                 {
  191.                     $html .= "GEvent.addListener(marker".$i.", \"click\", function(){
  192.                     marker".$i.".openInfoWindowHtml(\"".$infoText."\" );
  193.                     });
  194.                     ";
  195.                 }
  196.                
  197.                 $html .= "
  198.             });";
  199.         }
  200.        
  201.         $html .= "
  202.         }
  203.         \$(window).addEvent(\"load\", showGoogleMap);
  204.         </script>
  205.         ";
  206.        
  207.         return $html;
  208.     }
  209.    
  210.     public function xml2array($xml)
  211.     {
  212.         $this->depth = -1;
  213.         $xmlParser = xml_parser_create();
  214.         xml_set_object($xmlParser, $this);
  215.         xml_set_element_handler($xmlParser, "startElement", "endElement" );
  216.         xml_set_character_data_handler($xmlParser, "characterData" );
  217.         xml_parser_set_option($xmlParser, XML_OPTION_CASE_FOLDING, 0);
  218.         xml_parse($xmlParser, $xml, true);
  219.         xml_parser_free($xmlParser);
  220.        
  221.         return $this->xmlArray[0];
  222.     }
  223.    
  224.     public function startElement($parser, $name, $attribs)
  225.     {
  226.         $this->tags[] = $name;
  227.         $this->depth++;
  228.     }
  229.    
  230.     public function characterData($parser, $data)
  231.     {
  232.         $key = end($this->tags);
  233.         $this->xmlArray[$this->depth][$key] = $data;
  234.     }
  235.    
  236.     public function endElement($parser, $name)
  237.     {
  238.         $tag = array_pop($this->tags);
  239.         $childDepth = $this->depth + 1;
  240.         if(!empty($this->xmlArray[$childDepth]))
  241.         {
  242.             $this->xmlArray[$this->depth][$tag] = $this->xmlArray[$childDepth];
  243.             unset($this->xmlArray[$childDepth]);
  244.         }
  245.        
  246.         $this->depth--;
  247.     } 
  248.    
  249. }
  250. ?>


mood
Publicité
Posté le 04-02-2009 à 10:43:39  profilanswer
 

n°1847216
skeye
Posté le 04-02-2009 à 17:19:18  profilanswer
 

t'as qu'à tester si l'adresse est vide, et dans ce cas afficher une adresse "par défaut"...


---------------
Can't buy what I want because it's free -
n°1847234
marquito
Posté le 04-02-2009 à 17:35:23  profilanswer
 

si l'adresse est vide la carte ne s'affiche pas !
Je ne suis pas assez doué pour trouver mais je pense qu'il doit y avoir une condition genre renseignement obligatoire de l'adresse moi j'aimerai faire sauter cette condition pour que si l'utilisateur indique simplement sa ville la carte affiche la ville.
Peut être que c'est pas le bon fichier que je monte ?


Message édité par marquito le 04-02-2009 à 17:36:33
n°1847237
skeye
Posté le 04-02-2009 à 17:37:30  profilanswer
 

Dans ton putain de script, au lieu de transmettre l'adresse saisie directement, tu vérifies si c'est vide, et si c'est le cas tu transmets une adresse bidon.:o


---------------
Can't buy what I want because it's free -
n°1847293
marquito
Posté le 04-02-2009 à 20:20:06  profilanswer
 

une adresse bibon qui va afficher une carte de pétaouchnock !

n°1847297
skeye
Posté le 04-02-2009 à 20:32:51  profilanswer
 

marquito a écrit :

une adresse bibon qui va afficher une carte de pétaouchnock !


tu voudrais afficher quoi?[:el g]
Mets "France" comme adresse, si tu préfères :o


---------------
Can't buy what I want because it's free -
n°1847303
marquito
Posté le 04-02-2009 à 20:53:17  profilanswer
 

Non si l'utilisateur habite Marseille j'aimerai qu'il affiche Marseille et si je mets France où autre chose ça n'affiche rien la carte s'affiche que quand il y a une adresse moi j'aimerai ne pas rendre obligatoire ce champs adresse pour qu'il affiche au minimum la ville si l'adresse n'ai pas renseigné et si l'adresse est renseigné il affiche la rue. comme c'est le cas actuellement.


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

  Google Map

 

Sujets relatifs
Attendre le retour de Google Maps API avant de continuer le scriptGoogle analytics - expressions rationnelles
Publication d'une spreadsheet de Google Documents dans un postGoogle et la propriétée "visible"
Utilisation de Google Agenda dans application Web[Google Maps Api] Markers chronologique
Mettre des pub google dans son forumquestion Google Site Map
Google Map + Ancre htmlGoogle Map : plusieurs marqueurs
Plus de sujets relatifs à : Google Map


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