Titre: Aide : code non fonctionnel
Posté par: annoncetoi le le 30-09-2012 a 11:34:58
Bonjour, pourquoi ça ne marche qu'une fois sur 2 ? svp qui peut m'aider le code ne fonctionne que si une alerte est affichée. Sinon il n'affiche qu'un seul marker.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100% } </style> <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=***********&sensor=false"> </script> <script type="text/javascript"> var places = [{position: "75002, Paris", nom: "Paris 2"},{position: "93160, Noisy-le-Grand", nom: "Noisy"},{position: "75003, Paris", nom: "Paris 3"}]; function initialize() { var geocoder = new google.maps.Geocoder(); var mapOptions = { zoom: 7, mapTypeId: google.maps.MapTypeId.ROADMAP, };
var marker, i, tabmarker, infowindow; i=0; var infowindow = new google.maps.InfoWindow(); var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
for (var i=0;i<places.length; i++) {/* ça doit fonctionner si on ne passe pas par le géocodage */ geocoder.geocode({'address': places.position}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); var tabmarker = new Array(); tabmarker.push(marker = new google.maps.Marker({ map: map, position: results[0].geometry.location, })); } }); alert("le code ne fonctionne que si une alerte est affichée."); var contenu = places.nom + "<br><a href='" + places.nom + ".php'>un lien</a>"; setEventMarker(marker, infowindow, contenu); } }
google.maps.event.addDomListener(window, 'load', initialize); function setEventMarker(marker, infowindow, texte){ google.maps.event.addListener(marker, 'click', function() { infowindow.setContent(texte); infowindow.open(this.getMap(), this); }); }
</script>
</head> <body onload="initialize()"> <div id="map_canvas" style="width:100%; height:100%"></div> </body> </html>
http://annonce-toi.fr c'est pour afficher toutes les annonces avec photos texte dans une bulle |
Forum-webmaster | Actionné par YaBB SE
© 2001-2003, YaBB SE Dev Team. Tous droits réservés.
|