Précédent   Forum des professionnels en informatique > PHP > Langage > Débuter
Débuter Forum d'entraide pour débuter en PHP. Avant de poster -> Cours PHP, FAQ PHP, Outils PHP, etc.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 19/04/2011, 14h08   #1
Membre du Club
 
Inscription : juin 2007
Messages : 336
Détails du profil
Informations forums :
Inscription : juin 2007
Messages : 336
Points : 48
Points : 48
Par défaut Google maps Local/online

Bonjour le forum,

J'arrive à faire fonctionner un script qui affiche une carte google maps.
Le problème est que le script fonctionne bien sur wamp en local mais quand je le met en ligne la carte google n'affiche rien, et j'avoue que je ne sais pas pourquoi.
Voici le code :
Code :
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
<html>
    <?php
    //on inclus le fichier necessaire
    require('gmap.class.php');
    //On appel la classe
    $gmap = new GoogleMapAPI('map','google map');
    //ici on met la cle recuperé sur http://code.google.com/apis/maps/signup.html
    $gmap->setAPIKey('ma clef google api"');
    //hauteur en px
    $gmap->setHeight("600");
    //largeur en px
    $gmap->setWidth("1000");
    // si vous voulez ajouter les  boutons map/satellite/les 2
    $gmap->enableTypeControls();
    //on affiche map/satellite/les 2 au depart(hybrid,map,satellite)
    $gmap->setMapType('map');
    //si vous voulez mettre les lien vers marker il faut mettre enable
    $gmap->disableSidebar();
    //zomm automatique pour voir tous les marker
    $gmap->enableZoomEncompass();
    //trace en trait entre 2 points
    //$gmap->addPolyLineByAddress('adresse1','adresse2','#000000',2,100);
    //la mini map en bas a droite
    $gmap->enableOverviewControl();
    //on ajoute un marker par adresse
    $gmap->addMarkerByAddress("rue nationale lille france","rue nationale lille france");
    $gmap->printHeaderJS();
    ?>
    <body onload="onLoad()">
      <?php
        $gmap->printMapJS();
        $gmap->printMap();
        //si vous avez mis enable sidebar
        //$gmap->printSidebar();
      ?>
</html>
Merci de votre aide :-)
yuyu599 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 19/04/2011, 22h16   #2
Modérateur
 
Avatar de Vil'Coyote
 
Développeur Web
Inscription : février 2008
Messages : 3 302
Détails du profil
Informations personnelles :
Âge : 31
Localisation : France, Marne (Champagne Ardenne)

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : février 2008
Messages : 3 302
Points : 4 480
Points : 4 480
de mémoire la clé google ne peut être utilisé que pour une seule url. donc si tu as une clé valide pour ton PC, il t'en faut une différente pour ton site une fois hébergé.
Vil'Coyote est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/04/2011, 08h03   #3
Membre Expert
 
Avatar de transgohan
 
Homme Baptiste ROUSSEL
Étudiant
Inscription : janvier 2011
Messages : 802
Détails du profil
Informations personnelles :
Nom : Homme Baptiste ROUSSEL
Localisation : France, Territoire de Belfort (Franche Comté)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : janvier 2011
Messages : 802
Points : 1 515
Points : 1 515
Et si ce n'est pas cela penses à activer l'affichage des erreurs sur ton serveur.
transgohan est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/04/2011, 10h57   #4
Membre du Club
 
Inscription : juin 2007
Messages : 336
Détails du profil
Informations forums :
Inscription : juin 2007
Messages : 336
Points : 48
Points : 48
Bonjour,
merci pour vos réponses.
Alors la clef est bien valide car configurée pour ce ndd.
Si ce n'était pas le cas j'aurais eu une pop up me le signifiant.

Ensuite je ne sais pas comment voir les erreurs sur un server Je suis chez ovh en mutu donc je ne sais pas si cela est possible.

Mais j'ai identifié un élément.
Quand j'execute le script en local, mon code source sur le navigateur est celui ci :
Code :
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
<html>
    <script src="http://maps.google.com/maps?file=api&v=2&key=Ici ma clef API" type="text/javascript" charset="utf-8"></script>    <body onload="onLoad()">
      <script type="text/javascript" charset="utf-8">
//<![CDATA[
/*************************************************
 * Created with GoogleMapAPI 2.2
 * Author: Monte Ohrt <monte AT ohrt DOT com>
 * Copyright 2005-2006 New Digital Group
 * http://www.phpinsider.com/php/code/GoogleMapAPI/
 *************************************************/
var points = [];
var markers = [];
var counter = 0;
var to_htmls = [];
var from_htmls = [];
var map = null;
function onLoad() {
if (GBrowserIsCompatible()) {
var mapObj = document.getElementById("map");
if (mapObj != "undefined" && mapObj != null) {
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(50.6330986, 3.0533023), 16, G_NORMAL_MAP);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
map.addControl(new GOverviewMapControl());
var point = new GLatLng(50.6330986,3.0533023);
var marker = createMarker(point,"rue nationale lille france","<div id=\"gmapmarker\">rue nationale lille france</div>", 0);
map.addOverlay(marker);
}
} else {
alert("Sorry, the Google Maps API is not compatible with this browser.");
}
}
function createMarker(point, title, html, n) {
if(n >= 0) { n = -1; }
var marker = new GMarker(point);
var tabFlag = isArray(html);
if(!tabFlag) { html = [{"contentElem": html}]; }
to_htmls[counter] = html[0].contentElem + '<p /><form class="gmapDir" id="gmapDirTo" style="white-space: nowrap;" action="http://maps.google.com/maps" method="get" target="_blank">' +
                     '<span class="gmapDirHead" id="gmapDirHeadTo">Directions: <strong>To here</strong> - <a href="javascript:fromhere(' + counter + ')">From here</a></span>' +
                     '<p class="gmapDirItem" id="gmapDirItemTo"><label for="gmapDirSaddr" class="gmapDirLabel" id="gmapDirLabelTo">Start address: (include addr, city st/region)<br /></label>' +
                     '<input type="text" size="40" maxlength="40" name="saddr" class="gmapTextBox" id="gmapDirSaddr" value="" onfocus="this.style.backgroundColor = \'#e0e0e0\';" onblur="this.style.backgroundColor = \'#ffffff\';" />' +
                     '<span class="gmapDirBtns" id="gmapDirBtnsTo"><input value="Get Directions" type="submit" class="gmapDirButton" id="gmapDirButtonTo" /></span></p>' +
                     '<input type="hidden" name="daddr" value="' +
                     point.y + ',' + point.x + "(" + title.replace(new RegExp(/"/g),'"') + ")" + '" /></form>';
                      from_htmls[counter] = html[0].contentElem + '<p /><form class="gmapDir" id="gmapDirFrom" style="white-space: nowrap;" action="http://maps.google.com/maps" method="get" target="_blank">' +
                     '<span class="gmapDirHead" id="gmapDirHeadFrom">Directions: <a href="javascript:tohere(' + counter + ')">To here</a> - <strong>From here</strong></span>' +
                     '<p class="gmapDirItem" id="gmapDirItemFrom"><label for="gmapDirSaddr" class="gmapDirLabel" id="gmapDirLabelFrom">End address: (include addr, city st/region)<br /></label>' +
                     '<input type="text" size="40" maxlength="40" name="saddr" class="gmapTextBox" id="gmapDirSaddr" value="" onfocus="this.style.backgroundColor = \'#e0e0e0\';" onblur="this.style.backgroundColor = \'#ffffff\';" />' +
                     '<span class="gmapDirBtns" id="gmapDirBtnsFrom"><input value="Get Directions" type="submit" class="gmapDirButton" id="gmapDirButtonFrom" /></span></p' +
                     '<input type="hidden" name="daddr" value="' +
                     point.y + ',' + point.x + "(" + title.replace(new RegExp(/"/g),'"') + ")" + '" /></form>';
                     html[0].contentElem = html[0].contentElem + '<p /><div id="gmapDirHead" class="gmapDir" style="white-space: nowrap;">Directions: <a href="javascript:tohere(' + counter + ')">To here</a> - <a href="javascript:fromhere(' + counter + ')">From here</a></div>';
if(!tabFlag) { html = html[0].contentElem; }if(isArray(html)) { GEvent.addListener(marker, "click", function() { marker.openInfoWindowTabsHtml(html); }); }
else { GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); }); }
points[counter] = point;
markers[counter] = marker;
counter++;
return marker;
}
function isArray(a) {return isObject(a) && a.constructor == Array;}
function isObject(a) {return (a && typeof a == 'object') || isFunction(a);}
function isFunction(a) {return typeof a == 'function';}
function showInfoWindow(idx,html) {
map.centerAtLatLng(points[idx]);
markers[idx].openInfoWindowHtml(html);
}
function tohere(idx) {
markers[idx].openInfoWindowHtml(to_htmls[idx]);
}
function fromhere(idx) {
markers[idx].openInfoWindowHtml(from_htmls[idx]);
}
//]]>
</script>
<script type="text/javascript" charset="utf-8">
//<![CDATA[
if (GBrowserIsCompatible()) {
document.write('<div id="map" style="width: 1000px; height: 600px"></div>');
} else {
document.write('<b>Javascript must be enabled in order to use Google Maps.</b>');
}
//]]>
</script>
<noscript><b>Javascript must be enabled in order to use Google Maps.</b></noscript>
</html>
Mais mon code source sur mon site en ligne, j'ai ceci :
Code :
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
<html>
    <script src="http://maps.google.com/maps?file=api&v=2&key=Ma clef google ici" type="text/javascript" charset="utf-8"></script>    <body onload="onLoad()">
      <script type="text/javascript" charset="utf-8">
//<![CDATA[
/*************************************************
 * Created with GoogleMapAPI 2.2
 * Author: Monte Ohrt <monte AT ohrt DOT com>
 * Copyright 2005-2006 New Digital Group
 * http://www.phpinsider.com/php/code/GoogleMapAPI/
 *************************************************/
var points = [];
var markers = [];
var counter = 0;
var to_htmls = [];
var from_htmls = [];
var map = null;
function onLoad() {
if (GBrowserIsCompatible()) {
var mapObj = document.getElementById("map");
if (mapObj != "undefined" && mapObj != null) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
map.addControl(new GOverviewMapControl());
}
} else {
alert("Sorry, the Google Maps API is not compatible with this browser.");
}
}
function createMarker(point, title, html, n) {
if(n >= 0) { n = -1; }
var marker = new GMarker(point);
var tabFlag = isArray(html);
if(!tabFlag) { html = [{"contentElem": html}]; }
to_htmls[counter] = html[0].contentElem + '<p /><form class="gmapDir" id="gmapDirTo" style="white-space: nowrap;" action="http://maps.google.com/maps" method="get" target="_blank">' +
                     '<span class="gmapDirHead" id="gmapDirHeadTo">Directions: <strong>To here</strong> - <a href="javascript:fromhere(' + counter + ')">From here</a></span>' +
                     '<p class="gmapDirItem" id="gmapDirItemTo"><label for="gmapDirSaddr" class="gmapDirLabel" id="gmapDirLabelTo">Start address: (include addr, city st/region)<br /></label>' +
                     '<input type="text" size="40" maxlength="40" name="saddr" class="gmapTextBox" id="gmapDirSaddr" value="" onfocus="this.style.backgroundColor = \'#e0e0e0\';" onblur="this.style.backgroundColor = \'#ffffff\';" />' +
                     '<span class="gmapDirBtns" id="gmapDirBtnsTo"><input value="Get Directions" type="submit" class="gmapDirButton" id="gmapDirButtonTo" /></span></p>' +
                     '<input type="hidden" name="daddr" value="' +
                     point.y + ',' + point.x + "(" + title.replace(new RegExp(/"/g),'"') + ")" + '" /></form>';
                      from_htmls[counter] = html[0].contentElem + '<p /><form class="gmapDir" id="gmapDirFrom" style="white-space: nowrap;" action="http://maps.google.com/maps" method="get" target="_blank">' +
                     '<span class="gmapDirHead" id="gmapDirHeadFrom">Directions: <a href="javascript:tohere(' + counter + ')">To here</a> - <strong>From here</strong></span>' +
                     '<p class="gmapDirItem" id="gmapDirItemFrom"><label for="gmapDirSaddr" class="gmapDirLabel" id="gmapDirLabelFrom">End address: (include addr, city st/region)<br /></label>' +
                     '<input type="text" size="40" maxlength="40" name="saddr" class="gmapTextBox" id="gmapDirSaddr" value="" onfocus="this.style.backgroundColor = \'#e0e0e0\';" onblur="this.style.backgroundColor = \'#ffffff\';" />' +
                     '<span class="gmapDirBtns" id="gmapDirBtnsFrom"><input value="Get Directions" type="submit" class="gmapDirButton" id="gmapDirButtonFrom" /></span></p' +
                     '<input type="hidden" name="daddr" value="' +
                     point.y + ',' + point.x + "(" + title.replace(new RegExp(/"/g),'"') + ")" + '" /></form>';
                     html[0].contentElem = html[0].contentElem + '<p /><div id="gmapDirHead" class="gmapDir" style="white-space: nowrap;">Directions: <a href="javascript:tohere(' + counter + ')">To here</a> - <a href="javascript:fromhere(' + counter + ')">From here</a></div>';
if(!tabFlag) { html = html[0].contentElem; }if(isArray(html)) { GEvent.addListener(marker, "click", function() { marker.openInfoWindowTabsHtml(html); }); }
else { GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); }); }
points[counter] = point;
markers[counter] = marker;
counter++;
return marker;
}
function isArray(a) {return isObject(a) && a.constructor == Array;}
function isObject(a) {return (a && typeof a == 'object') || isFunction(a);}
function isFunction(a) {return typeof a == 'function';}
function showInfoWindow(idx,html) {
map.centerAtLatLng(points[idx]);
markers[idx].openInfoWindowHtml(html);
}
function tohere(idx) {
markers[idx].openInfoWindowHtml(to_htmls[idx]);
}
function fromhere(idx) {
markers[idx].openInfoWindowHtml(from_htmls[idx]);
}
//]]>
</script>
<script type="text/javascript" charset="utf-8">
//<![CDATA[
if (GBrowserIsCompatible()) {
document.write('<div id="map" style="width: 1000px; height: 600px"></div>');
} else {
document.write('<b>Javascript must be enabled in order to use Google Maps.</b>');
}
//]]>
</script>
<noscript><b>Javascript must be enabled in order to use Google Maps.</b></noscript>
</html>
On dirait qu'il ne comprend pas l'adresse ..
yuyu599 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/04/2011, 12h51   #5
Membre Expert
 
Avatar de transgohan
 
Homme Baptiste ROUSSEL
Étudiant
Inscription : janvier 2011
Messages : 802
Détails du profil
Informations personnelles :
Nom : Homme Baptiste ROUSSEL
Localisation : France, Territoire de Belfort (Franche Comté)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : janvier 2011
Messages : 802
Points : 1 515
Points : 1 515
Pour activer toutes les erreurs :
Code php :
error_reporting(-1);
transgohan est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/04/2011, 13h32   #6
Membre du Club
 
Inscription : juin 2007
Messages : 336
Détails du profil
Informations forums :
Inscription : juin 2007
Messages : 336
Points : 48
Points : 48
Bonjour,
J'ai inséré ce code juste avant " require('gmap.class.php');"
Mais rien de change et aucune erreur affichée.
Peut être que j'utilise mal la fonction ?
yuyu599 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/04/2011, 11h05   #7
Membre du Club
 
Inscription : juin 2007
Messages : 336
Détails du profil
Informations forums :
Inscription : juin 2007
Messages : 336
Points : 48
Points : 48
J'ai essayé de rebidouiller le code mais je n'obtiens pas mieux.
Auriez vous des pistes de reflexions ?
Je vous remercie par avance.
yuyu599 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/04/2011, 11h36   #8
Membre du Club
 
Inscription : juin 2007
Messages : 336
Détails du profil
Informations forums :
Inscription : juin 2007
Messages : 336
Points : 48
Points : 48
Bon après recherche il s'avère que google MAP V2 est obselète oO
Connaissez vous un tuto/lien pour afficher une carte google maps a partir d'une adresse stockée en base de donnée ? ( sans connaitre la longitude et la latitude )
yuyu599 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/04/2011, 13h55   #9
Membre du Club
 
Inscription : juin 2007
Messages : 336
Détails du profil
Informations forums :
Inscription : juin 2007
Messages : 336
Points : 48
Points : 48
En y allant étape par étape, j'arrive à afficher une carte depuis une variable php
Voici le code :
Code :
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
<!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" xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example: Asynchronous Data Retrieval</title>
 <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=MA clef google" type="text/javascript"></script>
  </head>
<?php
$toto ='Lille';
?>
  <body onload="initialize()" onunload="GUnload()">
    <div id="map_canvas" style="width: 500px; height: 300px"></div>
    <script type="text/javascript">
 var ville = [];
 var i = 0;
 var geocoder = new GClientGeocoder();
 var map = new GMap2(document.getElementById("map_canvas"));
 map.setCenter(new GLatLng(48, -3), 4);
    function initialize() {
      if (GBrowserIsCompatible()) {
    var dataxml="<markers><marker ville='<?php echo "$toto";?>' nom='60 rue national lille 59100'/></markers>";
    var xml = GXml.parse(dataxml);
    var markers = xml.documentElement.getElementsByTagName("marker");
    for (var i = 0; i < markers.length; i++)
     searchPoint(markers[i].getAttribute("ville"));
      }
    }
 
  function createMarker(point,city) {
 
   var marker = new GMarker(point);
   var lat=point.lat();
   var lng=point.lng();
   map.addOverlay(marker);
   GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(city);
   });
  }
  function searchPoint(point) {
   geocoder.getLatLng(point, function (coord){
    if (coord){
     createMarker(coord,point);
    }
   });
  }
    </script>
  </body>
</html>
Jusque la ok, sauf que mon problème viens du centrage de la map.
Car elle est définie comme telle : map.setCenter(new GLatLng(48, -3), 4);
Or je voudrais centrer la map sur mon adresse ( ma variable toto )
Savez vous quelle fonction utilisée ?
yuyu599 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/04/2011, 18h21   #10
Membre du Club
 
Inscription : juin 2007
Messages : 336
Détails du profil
Informations forums :
Inscription : juin 2007
Messages : 336
Points : 48
Points : 48
Bon j'ai résolu mon problème, pour ceux que sa intéresse il suffit de convertir son adresse en coordonnée GPS et de centrer la map dessus avec la fonction :
geocoder.getLatLng
yuyu599 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 06h39.


 
 
 
 
Partenaires

Hébergement Web