2017-11-04 2 views
-1

Ich benutze Google Maps API, ich möchte ein Infowindow für jeden Marker zeigen.Das gleiche Infowindow für jeden Marker anzeigen google maps api

Aber das Problem ist der gleiche Inhalt wird für jeden Marker Infowindow angezeigt. das heißt, in Infofenstern die letzte Zeichenfolge eines Arrays zeigt, obwohl ich Funktion verwendet habe bindInfoWindow() es nicht funktioniert:

ich Google Maps API verwenden, würde Ich mag ein Infofenster für jeden Marker zeigen.

Aber das Problem ist der gleiche Inhalt für jeden Marker infowindow.ie zeigt, die letzte Saite eines Arrays wird in Infofenster zeigt, obwohl ich Funktion verwendet haben bindInfoWindow() es funktioniert nicht:

var poly; 
var map; 
var infodatajson = [ 
    17.4172192, 78.401285, 
    17.418407, 78.401629, 
    17.418090, 78.400610, 
    17.417865, 78.398234 
]; 

// for center the map 
function initMap() { 
    map = new google.maps.Map(document.getElementById('map'), { 
    zoom: 15, 
    center: { 
     lat: 17.4172192, 
     lng: 78.401285 
    } 
    }); 

    // for polyline 
    var flightPlanCoordinates = new Array(); 

    for (i = 0; i < infodatajson.length; i += 2) { 
    var point = new google.maps.LatLng(infodatajson[i], infodatajson[i + 1]); 
    flightPlanCoordinates.push(point); 
    } 

    poly = new google.maps.Polyline({ 
    path: [new google.maps.LatLng(17.4172192, 78.401285), 
     new google.maps.LatLng(17.418407, 78.401629), 
     new google.maps.LatLng(17.418090, 78.400610), 
     new google.maps.LatLng(17.417865, 78.398234) 
    ], 
    geodesic: true, 
    strokeColor: '#0000FF', 
    strokeOpacity: 1.0, 
    strokeWeight: 3, 
    }); 

    var infowindow; 
    var infodata; 
    var marker; 

    // for markers 
    for (var i = 0, ln = infodatajson.length; i < ln; i += 2) { 

    infodata = infodatajson[i] + ", " + infodatajson[i + 1]; 

    marker = new google.maps.Marker({ 
     position: new google.maps.LatLng(infodatajson[i], infodatajson[i + 1]), 
     map: map, 
     title: infodatajson[i] + ", " + infodatajson[i + 1], 
    }); 

    infowindow = new google.maps.InfoWindow({}); 

    //function bindInfoWindow(marker, map, infowindow, infodata) {   
    marker.addListener('click', function() { 
    infowindow.setContent(infodata); 
    infowindow.open(map, this); 
    }); 
    //} 
    } 

    poly.setMap(map); 
} 
+0

ja, ich habe angerufen ** bindInfoWindow (Marker, Karte, Infofenster, INFODATA) ** obwohl seine nicht funktioniert – Naveen

Antwort

0

statt dies Ihrer bindInfoWindow() Funktion verwenden

google.maps.event.addListener(marker, 'click', function() { 
    infowindow.setContent(infodata); 
    infowindow.open(map, this); 
    }); 
+0

Arbeit nicht schon hatte ich getan, dass – Naveen

+0

können Sie s bitte hare your html, wo Sie diese Funktionen aufrufen? –

+0

Ja, Sie können in meinem Skript oben sehen – Naveen

Verwandte Themen