2017-11-04 9 views
-1

Google Maps APIを使用しています。すべてのマーカーについてインフォ画面を表示したいと思います。すべてのマーカーに同じ情報ウィンドウを表示するGoogleマップapi

しかし、問題はすべてのマーカー情報ウィンドウで同じコンテンツが表示されていることです。すなわち、配列の最後の文字列は、私は動作していない機能bindInfoWindow()を使用しているにもかかわらず、情報ウィンドウに表示されています。私はGoogle MapsのAPIを使用しています

、私はすべてのマーカーの情報ウィンドウ を表示したいと思います。代わりに

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

はい私は呼び出されています** bindInfoWindow(マーカー、マップ、情報ウィンドウ、infodata)**本家そのすでに私は – Naveen

答えて

0

しかし、問題は、同じコンテンツがすべてのマーカーinfowindow.ieに対して表示されており、配列の最後の文字列は、私はそれが動作していない機能bindInfoWindow()を使用しているにもかかわらず、情報ウィンドウに表示されますあなたのbindInfoWindow()関数の使用この

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

動作しませんこれらの関数を呼び出す場所はどこですか? – Naveen

+0

あなたはSを喜ばできることを行っていた作業ではない –

+0

はい、私は上記のスクリプトで見ることができます – Naveen

関連する問題