Problème affichage Google Map

Pi_Xi Messages postés 2274 Statut Membre -  
Pitet Messages postés 2845 Statut Membre -
Hello!

Je crois que mon PC est possédé... Je m'explique ^^

Je veux afficher une Google Map sur une page de mon site. Ca fait trois jours que je ne comprends pas pourquoi cela ne fonctionne pas....

Donc j'ai fait un fichier map_debug.php:

<?php

require("/map/GoogleMapAPIv3.class.php");

$map = new GoogleMapAPI('AIzaSyAOaUyZuCEJREgjapT6Wx3DRIuPuHhCS3U');

$map->setSize(600,400);
$map->setZoom(12);
$map->setDisplayDirectionFields(false);
$map->setDefaultHideMarker(true);
$map->generate();

var_dump($map);

echo $map->getGoogleMap();

?>

qui lui fonctionne !! :)

Cependant, si je fais un include de mon fichier qui marche, toujours pas de map !!!

Une idea? :p

4 réponses

  1. Pi_Xi Messages postés 2274 Statut Membre 149
     
    Résultat du var_dump():

    object(GoogleMapAPI)[3]
    protected 'googleMapId' => string 'googlemapapi' (length=12)
    protected 'googleMapDirectionId' => string 'route' (length=5)
    protected 'width' => int 250
    protected 'height' => int 100
    protected 'iconWidth' => int 20
    protected 'iconHeight' => int 34
    protected 'iconAnchorWidth' => int 0
    protected 'iconAnchorHeight' => int 0
    protected 'infoWindowWidth' => int 250
    protected 'zoom' => int 12
    protected 'enableWindowZoom' => boolean false
    protected 'infoWindowZoom' => int 6
    protected 'lang' => string 'fr' (length=2)
    protected 'center' => string 'Paris France' (length=12)
    protected 'content' => string ' <div id="googlemapapi" style="width:250;height:100"></div>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&key="AIzaSyAOaUyZuCEJREgjapT6Wx3DRIuPuHhCS3U"&language=fr"></script>
    <script type="text/javascript">
    function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
    window.onload = func;
    } else {
    window.onload = function() {
    if (oldonload) {
    oldonload();
    }
    func();
    }
    }
    }
    var geocoder = new google.maps.Geocoder();
    var m'... (length=4441)
    protected 'displayDirectionFields' => boolean false
    protected 'defaultHideMarker' => boolean true
    protected 'contentMarker' => string '' (length=0)
    protected 'useClusterer' => boolean false
    protected 'gridSize' => int 100
    protected 'maxZoom' => int 9
    protected 'clustererLibrarypath' => string 'http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer_packed.js' (length=111)
    protected 'enableAutomaticCenterZoom' => boolean false
    protected 'maxLng' => int -1000000
    protected 'minLng' => int 1000000
    protected 'maxLat' => int -1000000
    protected 'minLat' => int 1000000
    protected 'centerLat' => null
    protected 'centerLng' => null
    protected 'coordCoef' => float 0.01
    protected 'mapType' => string 'ROADMAP' (length=7)
    protected 'includeJs' => boolean true
    protected 'enableGeolocation' => boolean false
    0
  2. Pitet Messages postés 2845 Statut Membre 530
     
    Salut,

    Si je comprend bien map_debug.php quand tu l'appelles en direct, mais tu as une erreur quant tu l'inclus dans un autre fichier ?

    Le problème semble donc venir de l'autre fichier, c'est plutôt celui-ci qu'il faudrait nous montrer.

    Pense à activer le rapport d'erreur PHP avec l'affichage des erreurs et/ou à consulter le journal d'erreur PHP et nous indiquer quelles sont les erreurs.

    Bonne journée
    0
    1. Pi_Xi Messages postés 2274 Statut Membre 149
       
      Il n'y avait pas d'erreur !! (je développe depuis 10 ans en PHP & Cie maintenant hein)
      0
  3. Pi_Xi Messages postés 2274 Statut Membre 149
     
    L'erreur provient du DOCTYPE !!
    En effet, si je commente <!--DOCTYPE html-->
    j'ai bien ma map !!!

    Du coup, j'enquête sur les DOCTYPES !! :D
    0
  4. Pitet Messages postés 2845 Statut Membre 530
     
    https://stackoverflow.com/questions/9080575/google-map-api-doesnt-work-when-doctype-declared-in-chrome-and-firefox

    La hauteur de ton div contenant la map est égal à 0. Il suffit de lui définir une hauteur en css.
    0
    1. Pi_Xi Messages postés 2274 Statut Membre 149
       
      Alors j'ai bien essayé, sans succès.

      La hauteur du div n'est pas à zéro, je l'ai forcée!

      Cf code source:
      <div id="googlemapapi" style="width:400;height:200"></div>

      Voici un fichier d'exemple:
      <?php

      require('map/GoogleMapAPIv3.class.php');

      $mysqli = new Mysqli("xxx","xxx","","xxx") or die("Erreur lors de la connexion à la bdd");
      $req = "SELECT adresse,cp,ville,pays FROM xxx";
      $result = $mysqli->query($req) or die("Problème de requêtage sur:".$req);

      $map = new GoogleMapAPI('MaKey');
      $map->setSize(400,200);
      $map->setZoom(12);
      $map->setDefaultHideMarker(false);

      while($tab_pays = $result->fetch_assoc()){

      $ville = $tab_pays['ville'];
      $adresse = $tab_pays['adresse'];
      $pays = $tab_pays['pays'];
      $cp = $tab_pays['cp'];

      $map->setCenter($adresse.", ".$cp." ".$ville.", ".$pays);
      $map->addMarkerByAddress($adresse.", ".$cp." ".$ville.", ".$pays, 'xxx');
      }

      $map->generate();

      ?>

      <!DOCTYPE html>
      <html>
      <head>
      <title>Carte <?=$adresse?></title>
      </head>

      <body>

      <?php echo $map->getGoogleMap(); ?>

      </body>
      </html>

      Sans le doctype, affichage de ma carte!
      Avec le doctype html pas de map! :'(
      0
    2. Pitet Messages postés 2845 Statut Membre 530
       
      Et en précisant l'unité ?
      style="width:400px; height:200px"
      0