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

APIs Google Discussion :

problème affichage infowindow [Google Maps]


Sujet :

APIs Google

  1. #1
    Candidat au Club
    Femme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2012
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Février 2012
    Messages : 4
    Points : 4
    Points
    4
    Par défaut problème affichage infowindow
    Bonjour,
    j'ai utilisé ce code pour afficher infowindow.Le problème réside dans l'affichage des données:les données dans l'infobulle n'appartiennent pas à son marqueur, de plus lorsqu'on clique plusieurs fois sur le même marqueur,l''infobulle change.
    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
    <!DOCTYPE html>
    <html lang="fr">
    <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>[Google Maps API V3] Déplacement d'un Marker</title>
    <meta name="Author" content="NoSmoking">
    <style type="text/css">
    html, body {
      height : 100%;
      margin : 0;
      padding : 0;
      font-family : Verdana, Arial;
      font-size : 1em;
    }
    h1 {
      color : #4488bb;
      font-size : 1.3em;
      margin : 0;
      padding : 0.5em;
      border : 1px solid #4488bb;
    }
    #page {
      padding : 0.5em;
    }
    #div_main {
      margin : auto;
      width : 800px;
    }
    #div_carte{
      margin : auto;
      margin-top : 1.0em;
      width : 600px;
      height: 600px;
      border : 1px solid #c0c0c0;
    }
    </style>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
    var tPosition = [
      { 'lat' :45.767299, 'lon' : 4.834329},
      { 'lat' :48.856667, 'lon' : 2.350987},
      { 'lat' :44.837368, 'lon' :-0.576144},
      { 'lat' :43.297612, 'lon' : 5.381042}
    ];
     
    var nbPoint = tPosition.length;
    var iPos = 0;
     
    function movePositionMarker( marker, trajet){
      iPos++;            // incrémentation;
      iPos %= nbPoint;   // pas de débordement
     
      // cretaion d'un nouveau marqueur
      var oMarker = new google.maps.Marker({
          'position' : marker.getPosition(),  // position du marker en cours
          'map': marker.getMap()              // map du marker en cours
        });
     
    	// Encore quelques fonctions google maps pour ajouter un infobulle lors d'un clic sur un marqueur
    google.maps.event.addListener(oMarker, 'click', function() {
    var infowindow = new google.maps.InfoWindow({
      content:'',
      size: new google.maps.Size(50,50),
      position:point
     
    });
     //infowindow.open(map, marker);
      infowindow.open(marker.getMap(), this);
      infowindow.setContent('latitude :'+tPosition[iPos].lat+'<br>longitude :'+tPosition[iPos].lon+'');
    });	 
     
     
      // recup. du point a traiter
      var point = new google.maps.LatLng( tPosition[iPos].lat, tPosition[iPos].lon);
      // deplace le marker
      marker.setPosition( point);
      // ajout point dans polyline
      trajet.getPath().push( point);
      // rappel de la fonction
      setTimeout( function(){
          movePositionMarker( marker, trajet);
        }, 1000);
    }
     
    function initCarte(){
      // init
      var oMap, oMarker;
      var mapOptions = {
        backgroundColor : '#fff',
        mapTypeControl :  false,
        streetViewControl : false,
        zoomControlOptions: {
          style: google.maps.ZoomControlStyle.SMALL
        },
        zoom : 6,
        center : new google.maps.LatLng( 46.80, 1.75),
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      // creation de la carte
      oMap = new google.maps.Map(document.getElementById("div_carte"), mapOptions);
      // creation du marqueur
      oMarker = new google.maps.Marker({
        position : new google.maps.LatLng( tPosition[0].lat, tPosition[0].lon),
        map : oMap
      });
    var oPolyline = new google.maps.Polyline({
        'map': oMap
      });
      movePositionMarker( oMarker,oPolyline);
    }
    // init lorsque la page est chargee
    google.maps.event.addDomListener(window, 'load', initCarte);
    </script>
    </head>
    <body>
    <div id="page">
      <div id="div_main">
        <h1>[Google Maps API V3] Déplacement d'un Marker</h1>
        <div id="div_carte"></div>
      </div>
    </div>
    </body>
    </html>
    qlqu'un peut m'aider
    Merci d'avance.

  2. #2
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    16 959
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 16 959
    Points : 44 122
    Points
    44 122
    Par défaut
    Bonjour,
    une seule adresse Sommaire > Google Maps

  3. #3
    Candidat au Club
    Femme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2012
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Février 2012
    Messages : 4
    Points : 4
    Points
    4
    Par défaut problème affichage infowindow
    merci beaucoup NoSmoking,
    je l'ai corrigé voilà le code correcte:
    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
    <!DOCTYPE html>
    <html lang="fr">
    <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>[Google Maps API V3] Déplacement d'un Marker</title>
    <meta name="Author" content="NoSmoking">
    <style type="text/css">
    html, body {
      height : 100%;
      margin : 0;
      padding : 0;
      font-family : Verdana, Arial;
      font-size : 1em;
    }
    h1 {
      color : #4488bb;
      font-size : 1.3em;
      margin : 0;
      padding : 0.5em;
      border : 1px solid #4488bb;
    }
    #page {
      padding : 0.5em;
    }
    #div_main {
      margin : auto;
      width : 800px;
    }
    #div_carte{
      margin : auto;
      margin-top : 1.0em;
      width : 600px;
      height: 600px;
      border : 1px solid #c0c0c0;
    }
    </style>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
    var tPosition = [
      { 'lat' :45.767299, 'lon' : 4.834329},
      { 'lat' :48.856667, 'lon' : 2.350987},
      { 'lat' :44.837368, 'lon' :-0.576144},
      { 'lat' :43.297612, 'lon' : 5.381042},
     
    ];
     
    var nbPoint = tPosition.length;
    var iPos = 0;
    var i=0;
    function movePositionMarker( marker, trajet){
     
     
     // iPos %= nbPoint;   // pas de débordement
     
      // cretaion d'un nouveau marqueur
      var oMarker = new google.maps.Marker({
          'position' : marker.getPosition(),  // position du marker en cours
          'map': marker.getMap()              // map du marker en cours
        });
     
     
      var cont='latitude :'+tPosition[i].lat+'<br>longitude :'+tPosition[i].lon+'<br>position :'+i+'';
    	// Encore quelques fonctions google maps pour ajouter un infobulle lors d'un clic sur un marqueur
    google.maps.event.addListener(oMarker, 'click', function() {
    var infowindow = new google.maps.InfoWindow({
      content:cont,
      size: new google.maps.Size(50,50),
     
    });
     //infowindow.open(map, marker);
      infowindow.open(marker.getMap(), oMarker);
      //infowindow.setContent('latitude :'+tPosition[iPos+1].lat+'<br>longitude :'+tPosition[iPos+1].lon+'');
    });	  
     iPos++; 	 i=iPos-1;     // incrémentation;
      // recup. du point a traiter
     //  var point = new google.maps.LatLng( tPosition[iPos].lat, tPosition[iPos].lon);
      var point1 = new google.maps.LatLng( tPosition[i].lat, tPosition[i].lon);
      // deplace le marker
      marker.setPosition( point1);
      // ajout point dans polyline
      trajet.getPath().push( point1);
      // rappel de la fonction
      setTimeout( function(){
          movePositionMarker( marker, trajet);
        }, 1000);
     
    }
     
    function initCarte(){
      // init
      var oMap, oMarker;
      var mapOptions = {
        backgroundColor : '#fff',
        mapTypeControl :  false,
        streetViewControl : false,
        zoomControlOptions: {
          style: google.maps.ZoomControlStyle.SMALL
        },
        zoom : 6,
        center : new google.maps.LatLng( 46.80, 1.75),
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      // creation de la carte
      oMap = new google.maps.Map(document.getElementById("div_carte"), mapOptions);
      // creation du marqueur
      oMarker = new google.maps.Marker({
        position : new google.maps.LatLng( tPosition[0].lat, tPosition[0].lon),
        map : oMap
      });
    var oPolyline = new google.maps.Polyline({
        'map': oMap
      });
      movePositionMarker( oMarker,oPolyline);
    }
    // init lorsque la page est chargee
    google.maps.event.addDomListener(window, 'load', initCarte);
    </script>
    </head>
    <body>
    <div id="page">
      <div id="div_main">
        <h1>[Google Maps API V3] Déplacement d'un Marker</h1>
        <div id="div_carte"></div>
      </div>
    </div>
    </body>
    </html>

  4. #4
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    16 959
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 16 959
    Points : 44 122
    Points
    44 122
    Par défaut
    ta gestion des marqueurs est un peu à l'arrache, pas de condition d'arrêt lorsque tu arrives à la fin de la liste.

    Un des effets de bord est que lorsque tu cliques plusieurs fois sur un marqueur tu ouvres autant d'infoWindow!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 10
    Dernier message: 08/06/2009, 11h30
  2. problème affichage image
    Par thealpacino dans le forum Balisage (X)HTML et validation W3C
    Réponses: 8
    Dernier message: 30/05/2005, 13h56
  3. Problème affichage primitive
    Par goutbouyo dans le forum DirectX
    Réponses: 4
    Dernier message: 29/12/2004, 18h25
  4. [Plugin][VE] Problème affichage
    Par sebb84 dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 05/07/2004, 14h50
  5. [DOS] Problème affichage de DOS dans un Memo
    Par Pedro dans le forum API, COM et SDKs
    Réponses: 9
    Dernier message: 25/06/2004, 13h31

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