Bonsoir,
J'ai intégré dans mon site une rubrique qui fait appel à des Google Maps.
Grosso-modo, Un rédacteur ajoute un article, contenant un nom de ville, et une map apparait automatiquement dans l'article après un appel au geocoder.
Le souci c'est que jusqu'à maintenant j'ai crée une fonction de traitement gmap par article (c'est moche je sais) et que le nombre d'articles par page se doit donc d'être fixe.
J'aimerais donc réaliser une fonction générique pour le geocoding et l'initialisation d'un google map.
Un peu de code pour expliciter tout ça :
Les fonctions d'initialisations :
Code :
- <script type="text/javascript">
- var map1 = null;
- var map2 = null;
- var map3 = null;
- var geocoder = null;
- function initialize1() {
- if (GBrowserIsCompatible()) {
- map1 = new GMap2(document.getElementById("map_canvas1" ));
- geocoder = new GClientGeocoder();
- }
- }
- function showAddress1(address) {
- if (geocoder) {
- geocoder.getLatLng(
- address,
- function(point) {
- if (!point) {
- alert(address + " not found" );
- } else {
- map1.setCenter(point, 11);
- var marker = new GMarker(point);
- map1.addOverlay(marker);
- marker.openInfoWindowHtml(address);
- }
- }
- );
- }
- }
- function initialize2() {
- if (GBrowserIsCompatible()) {
- map2 = new GMap2(document.getElementById("map_canvas2" ));
- geocoder = new GClientGeocoder();
- }
- }
- function showAddress2(address) {
- if (geocoder) {
- geocoder.getLatLng(
- address,
- function(point) {
- if (!point) {
- alert(address + " not found" );
- } else {
- map2.setCenter(point, 11);
- var marker = new GMarker(point);
- map2.addOverlay(marker);
- marker.openInfoWindowHtml(address);
- }
- }
- );
- }
- }
|
L'affichage :
Code :
- pour i allant de 1 au nombre d'article par page {
- echo"<div id='map_canvas".$i."' style='width: 400px; height: 300px'></div>";
- echo"<script type='text/javascript'>initialize".$i."(); showAddress".$i."('".$lieu." ".$cp."');</script>";
- $i = $i +1;
- }
|
Merci d'avance 
Message édité par darkgloom le 20-12-2009 à 19:18:21