0

J'ai une carte google et des marqueurs dessus. Les marqueurs peuvent se déplacer comme le suivi des véhicules.J'ai réussi à déplacer les marqueurs selon les nouvelles données de localisation.Il n'y a pas de problème ici.Lorsqu'un clic sur un marqueur, un infowindow qui a des informations de localisation (lng & ltd) est ouvert.Mais si le marqueur déplace un autre emplacement infowindow est ouvert, le contenu (information de localisation) d'infowindow ne change pas. Comment changer le contenu d'infowindow avec de nouvelles informations de localisation pendant que le marqueur se déplace?comment actualiser le contenu de l'infowindow déjà ouvert de google maps lorsque la position du marqueur est actualisée?

S'il vous plaît aidez-moi à surmonter le problème? La création de marqueurs est tout d'abord comme suit:

var mapOptions = { 
     zoom: 10, 
     center: new google.maps.LatLng(37.2312, 36.9041), 
     mapTypeId: google.maps.MapTypeId.SATELLITE, 
     disableDefaultUI: false, 
     zoomControl: true 
    }; 
var map = new google.maps.Map(document.getElementById('pnlMap'), mapOptions); 
var latlng = new google.maps.LatLng(coordinateInfo[1].replace(',', '.'), coordinateInfo[0].replace(',', '.')); 
        bounds.extend(latlng); 

        var marker = new google.maps.Marker({ 
         position: latlng, 
         map: map, 
         icon: '../images/ship_icon.png', 
         store_id: coordinateInfo[3], 
         title: coordinateInfo[2] 
        }); 
        markerList.push(marker); 

        (function (marker, coordinateInfo) { 
         google.maps.event.addListener(marker, "click", function (e) { 
          infoWindow.setContent(
         '<div id="iw-container">' + 
          '<div class="iw-title">' + coordinateInfo[2] + 
           '<div class="iw-content">' + 
         '<table class="zebra"> <tr> <td><b>Gemi Adı : </b></td> <td>' + coordinateInfo[2] + '</td> </tr> <tr> <td><b>Cihaz ID Numarası : </b></td> <td>' + coordinateInfo[3] + '</td> </tr> <tr> <td><b>Koordinat Bilgileri(X,Y) : </b></td> <td>' + coordinateInfo[0] + ' - ' + coordinateInfo[1] + '</td> </tr> <tr> <td><b>Telefon Numarası : </b></td> <td>' + coordinateInfo[9] + '</td> </tr> <tr> <td><b>Telsiz Numarası : </b></td> <td></td> </tr> <tr> <td><b>Hız : </b></td> <td>' + coordinateInfo[6] + '</td> </tr> <tr> <td><b>Gps Zamanı : </b></td> <td>' + coordinateInfo[10] + '</td> </tr> <tr> <td><b>Konum : </b></td> <td>' + coordinateInfo[11] + '</td> </tr> </table>' + 
          '</div>' + 
         '</div>'); 
          infoWindow.maxWidth = 380; 
          infoWindow.maxWidth = 380; 
          infoWindow.open(map, marker); 
         }); 
        })(marker, coordinateInfo); 

        google.maps.event.addListener(map, 'click', function() { 
         infoWindow.close(); 
        }); 

marqueurs de mise à jour de la nouvelle position est la suivante;

for (var k = 0; k < coordinateLength - 1; k++) { 
        var coordinateInfoTemp = coordinates[k].split("~"); 
        for (var j = 0; j < markerList.length; j++) { 
         var markerTmp = markerList[j]; 
         if (markerTmp.store_id === coordinateInfoTemp[3]) { 
          var latlngNew = new google.maps.LatLng(coordinateInfoTemp[1].replace(',', '.'), coordinateInfoTemp[0].replace(',', '.')); 
          markerTmp.setPosition(latlngNew); 
          (function (markerTmp, coordinateInfoTemp) { 
           google.maps.event.addListener(markerTmp, "click", function (e) { 
            alert(coordinateInfoTemp[10]); 
            infoWindow.setContent(
                  '<div id="iw-container">' + 
                   '<div class="iw-title">' + coordinateInfoTemp[2] + 
                    '<div class="iw-content">' + 
                  '<table class="zebra"> <tr> <td><b>Gemi Adı : </b></td> <td>' + coordinateInfoTemp[2] + '</td> </tr> <tr> <td><b>Cihaz ID Numarası : </b></td> <td>' + coordinateInfoTemp[3] + '</td> </tr> <tr> <td><b>Koordinat Bilgileri : </b></td> <td>' + coordinateInfoTemp[0] + ' - ' + coordinateInfoTemp[1] + '</td> </tr> <tr> <td><b>Telefon Numarası : </b></td> <td>' + coordinateInfoTemp[9] + '</td> </tr> <tr> <td><b>Telsiz Numarası : </b></td> <td></td> </tr> <tr> <td><b>Hız : </b></td> <td>' + coordinateInfoTemp[6] + '</td> </tr> <tr> <td><b>Gps Zamanı : </b></td> <td>' + coordinateInfoTemp[10] + '</td> </tr> </table>' + 
                   '</div>' + 
                  '</div>'); 
            infoWindow.maxWidth = 380; 
            infoWindow.refresh(); 
           }); 
          })(markerTmp, coordinateInfoTemp); 
          break; 
         } 
        } 
       } 

Merci d'avance.

SOLUTION

J'ai trouvé la solution en ajoutant le contrôle suivant, quand je clique sur un marqueur, je suis en train markerTmp.store_id à selectedMarkerStoreId variable;

if (selectedMarkerStoreId != null && selectedMarkerStoreId === markerTmp.store_id) { 
            infoWindow.setContent(markerTmp.htmlContent); 
           } 
+0

Ajouter un code à votre question qui illustre le problème – duncan

+0

Sur la base de ce [tutoriel] (http://itpscan.info/examples/google_maps/maps_01a/), vous devez fermer la fenêtre d'information d'abord pour pouvoir actualiser son contenu. Voir [Modification du contenu de la fenêtre d'informations dans google maps api v3] (http://stackoverflow.com/a/13750844/5995040) et [Modification du code HTML de Google Maps Marker après l'exécution d'une fonction] (http: // stackoverflow. com/a/13504662/5995040) sur la modification de 'infowindow' en modifiant le DOM. –

+0

@ Mr.Rebot remercie votre partage, mais ceux-ci ne m'a pas aidé et de présenter un moyen de rafraîchir le contenu de "open" infowindow sans le fermer. – user6493966

Répondre

0

Je suppose que vous avez un seul infowindow, alors tout u besoin de faire est d'ajouter un écouteur pour rafraîchir le contenu du infowindow

marker.addListener('click', function() { 
     var content = '<p>Lat:'+this.getPosition().lat()+'</p><p>Lng:'+ this.getPosition().lng(); 
     infowindow.setContent(content); 
     infowindow.open(yourmap,this); 
    }); 

espère que cela aide.

MISE À JOUR:

for (var k = 0; k < coordinateLength - 1; k++) { 
       var coordinateInfoTemp = coordinates[k].split("~"); 
       for (var j = 0; j < markerList.length; j++) { 
        var markerTmp = markerList[j]; 
        if (markerTmp.store_id === coordinateInfoTemp[3]) { 
         var latlngNew = new google.maps.LatLng(coordinateInfoTemp[1].replace(',', '.'), coordinateInfoTemp[0].replace(',', '.')); 
         markerTmp.setPosition(latlngNew); 
         infowindow.setContent(yourcontent);//update here 
         break; 
        } 
       } 
      } 
+0

Merci @RoolearnGear, codez ce que vous partagez fonctionne sur l'événement de clic, mais je veux déclencher l'opération d'actualisation infowindow sur le changement de position du marqueur alors que infowindow est déjà ouvert. Est-ce que votre code m'aide? – user6493966

+0

que diriez-vous juste de définir le contenu lorsque vous mettez à jour le marqueur? – RoolearnGear

+0

J'ai raté cette partie, j'ai ajouté maintenant. – user6493966