IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

Google map markers


Sujet :

JavaScript

  1. #1
    Membre du Club
    Inscrit en
    Janvier 2008
    Messages
    139
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 139
    Points : 57
    Points
    57
    Par défaut Google map markers
    onjour,
    voila mon probleme:
    je comprends pas pourquoi mes markers cree ne contiennent que la variable address2 et de plus tous les markers ont la meme valeur pour la variable address2...
    Si quelqu'un voit pourquoi ca fonctionne pas je lui en serait infiniement reconnaissant...

    Code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    var map;
    var localSearch = new GlocalSearch();
    var address2;
    var address3;
    var postcode;
    var img;
    var icon = new GIcon();
     
    icon.image = "http://images.google.com/mapfiles/marker.png";
    icon.iconSize = new GSize(20, 30);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(10, 34);
     
     
    function usePointFromPostcode(postcode,callbackFunction) {
     
        localSearch.setSearchCompleteCallback(null,
            function() {
     
                if (localSearch.results[0])
                {       
                    var resultLat = localSearch.results[0].lat;
                    var resultLng = localSearch.results[0].lng;
                    var point = new GLatLng(resultLat,resultLng);
                    callbackFunction(point, address2, address3, postcode,img);
                }else{
                    alert("Postcode not found!");
                }
            });   
     
        localSearch.execute(postcode + ", UK");
        }
     
    //function placeMarkerAtPoint(point)
    //{
    //    var marker = new GMarker(point,icon);
    //    map.addOverlay(marker);
    //}
     
    function setCenterToPoint(point)
    {
        map.setCenter(point, 15);
        var marker = new GMarker(point,icon);
        map.addOverlay(marker);
        map.openInfoWindow(map.getCenter(),"<img src='http://localhost/Smart/images/icon_map.gif' />");
        }
     
    function showPointLatLng(point)
    {
        var Latitude = point.lat();
        var Longitude = point.lng();
     
        }
     
    function mapLoad() {
        if (GBrowserIsCompatible()) {
            map = new GMap2(document.getElementById("map"));
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            map.setCenter(new GLatLng(54.622978,-2.592773), 5, G_NORMAL_MAP);
        }
    }
     
     
    GDownloadUrl("http://localhost/Smart/XmlGmap.php",function(data) {
      var xml = GXml.parse(data);
      var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
            address2 = markers[i].getAttribute("address2");
            address3 = markers[i].getAttribute("address3");
            postcode = markers[i].getAttribute("postcode");
            img = markers[i].getAttribute("img1");
            alert("attention"+address2 );
            usePointFromPostcode(postcode,createMarker);
            //alert("valeur lon: "+Longitude);
            //alert("valeur la: "+Latitude);
            //var point = new GLatLng(Latitude,Longitude);
            //var marker = createMarker(point, address2, address3, postcode,img);
     
     
      }
    });
     
     
     
    function createMarker(point, address2, address3, postcode,img) {
      var marker = new GMarker(point, icon);
      alert(address2);
      alert(address3);
      alert(img);
      var html = "<b>" + address3 + "</b> <br/>" + address2;
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
     map.addOverlay(marker);
      //return marker;
    }
     
     
     
     
     
    function addLoadEvent(func) {
      var oldonload = window.onload;
      if (typeof window.onload != 'function') {
        window.onload = func;
      } else {
        window.onload = function() {
          oldonload();
          func();
        }
      }
    }
     
    function addUnLoadEvent(func) {
        var oldonunload = window.onunload;
        if (typeof window.onunload != 'function') {
          window.onunload = func;
        } else {
          window.onunload = function() {
            oldonunload();
            func();
          }
        }
    }
     
    addLoadEvent(mapLoad);
    addUnLoadEvent(GUnload);

  2. #2
    Membre du Club
    Inscrit en
    Janvier 2008
    Messages
    139
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 139
    Points : 57
    Points
    57
    Par défaut
    j'ai ciblé mon probleme c'est mon appel de focntion qui deconne.
    Lorsque j'appel "usePointFromPostcode(postcode,createMarker);" et bien dans la fonction "usePointFromPostcode(postcode,callbackFunction)" ,ma callbackfonction (createMarker) est appelé lorsque ma boucle qui parcours mon XML est fini. et c'est pour
    ça que je me retrouve avec mon dernier enregistrement de ma table dans mon marqueur. Il crée donc tous les marqueur en fonction du dernier enregistrement de ma table...
    Une idée, pourquoi il me fait ca?

  3. #3
    Membre du Club
    Inscrit en
    Janvier 2008
    Messages
    139
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 139
    Points : 57
    Points
    57
    Par défaut
    J'ai trouver a force de tester: c'est mon appelle a mon fonction callback qui est fait de facon asynchrone qui planté tout. je ne comprends toujours pas pourquoi ca fonctionnait pas avant. Mais en étudiant mon probleme je me suis rendu compte que l appel a ma callback fonction se faisait a la fin donc j'ai tout simplement remplacer mes variables par des tableau (tanpis pour la mémoire)



    ca donne ca:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
     
     
     
     
    var map;
    var localSearch = new GlocalSearch();
    var saveTown=[];
    var savePostcode=[];
    var saveStreet=[];
    var saveImg=[];
    var icon = new GIcon();
    var j=0;
     
    icon.image = "http://images.google.com/mapfiles/marker.png";
    icon.iconSize = new GSize(20, 30);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(10, 34);
     
     
    function usePointFromPostcode(postcode,callbackFunction) {
     
    	localSearch.setSearchCompleteCallback(null, 
    		function() {
     
    			if (localSearch.results[0])
    			{	
    				var resultLat = localSearch.results[0].lat;
    				var resultLng = localSearch.results[0].lng;
    				var point = new GLatLng(resultLat,resultLng);
    				callbackFunction(point);
    			}else{
    				alert(postcode+"not found!");
    			}
    		});	
    		localSearch.execute(postcode + ", UK");
    	}
     
     
    function setCenterToPoint(point)
    {
    	map.setCenter(point, 15);
     
    	}
     
    function showPointLatLng(point)
    {
    	var Latitude = point.lat();
        var Longitude = point.lng();
    	alert("attention");
     
    	}
     
    function mapLoad() {
    	if (GBrowserIsCompatible()) {
    		map = new GMap2(document.getElementById("map"));
    		map.addControl(new GSmallMapControl());
    		map.addControl(new GMapTypeControl());
    		map.setCenter(new GLatLng(54.622978,-2.592773), 5, G_NORMAL_MAP);
    	}
    }
     
     
    GDownloadUrl("http://localhost/Smart/XmlGmap.php",function(data) {
      var xml = GXml.parse(data);
      var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
    		address2 = markers[i].getAttribute("address2");
    	    address3 = markers[i].getAttribute("address3");
    	    postcode = markers[i].getAttribute("postcode");
    		img = markers[i].getAttribute("img1");
    		usePointFromPostcode(postcode,createMarker);
    		saveTown[i]=address2;
    		savePostcode[i]=postcode;
            saveStreet[i]=address3;
            saveImg[i]=img;
    	}
    });
     
     
     
    function createMarker(point) {
      var marker = new GMarker(point, icon);
      var html = "<div id='mapImage'><img src='http://localhost/Smart/"+saveImg[j]+"' width='100' height='80'/></div><div><b>" +savePostcode[j]+" "+saveTown[j] + "</b><br/>" + saveStreet[j]+"</div>";
      j=j+1;
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
     map.addOverlay(marker);
      //return marker;
    }
     
     
     
     
     
    function addLoadEvent(func) {
      var oldonload = window.onload;
      if (typeof window.onload != 'function') {
        window.onload = func;
      } else {
        window.onload = function() {
          oldonload();
          func();
        }
      }
    }
     
    function addUnLoadEvent(func) {
    	var oldonunload = window.onunload;
    	if (typeof window.onunload != 'function') {
    	  window.onunload = func;
    	} else {
    	  window.onunload = function() {
    	    oldonunload();
    	    func();
    	  }
    	}
    }
     
    addLoadEvent(mapLoad);
    addUnLoadEvent(GUnload);

    si quelqu'un par contre pourrait m'expliquer pourquoi mon callback n'est pas effectué directement ca serait sympa.

Discussions similaires

  1. [Google Maps] Markers par adresse
    Par hbhhhbhh dans le forum APIs Google
    Réponses: 5
    Dernier message: 10/04/2009, 17h49
  2. google map, cercle et marker
    Par zn415 dans le forum Général JavaScript
    Réponses: 0
    Dernier message: 07/09/2008, 16h57
  3. API Google Map et markers en XML
    Par greichka dans le forum APIs
    Réponses: 8
    Dernier message: 21/05/2008, 12h05
  4. Google Map : Menu liste de marker -> Affiche marker
    Par aurore22 dans le forum Général JavaScript
    Réponses: 0
    Dernier message: 18/05/2008, 10h55
  5. Text info bulle marker google map
    Par devadip dans le forum Général JavaScript
    Réponses: 0
    Dernier message: 25/01/2008, 12h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo