0

Please look at my code. Where is the problem? When i call this function coordinates now work normally( lines not working) and info windows also not working.

So when delete function binfowindow everything is working but infowindow show only last data..

Updated! Not a result!

 function getline() {

       var mpenc = new google.maps.InfoWindow();   
downloadUrl("line.php", function(doc) {



        var g = google.maps;

        var xmlDoc = xmlParse(doc);

        bounds = new google.maps.LatLngBounds();
        var markers = xmlDoc.documentElement.getElementsByTagName("marker");
      // ========= Now process the polylines ===========
      var lines = xmlDoc.documentElement.getElementsByTagName("line");

      // read each line
      for (var a = 0; a < lines.length; a++) {
        // get any line attributes
       var colour = lines[a].getAttribute("colour");
        var width  = parseFloat(lines[a].getAttribute("width"));
        var diameter = lines[a].getAttribute("diameter");
        var project = lines[a].getAttribute("projectid");
        var contract = lines[a].getAttribute("contract");
        var comp = lines[a].getAttribute("complated");
        var id = lines[a].getAttribute("id_line");
        var html = "men ?" + id + " I: ";
        // read each point on that line
        var points = lines[a].getElementsByTagName("point");
        var pts = [];
        var length = 0;
        var point = null;
        for (var i = 0; i < points.length; i++) {
           pts[i] = new g.LatLng(parseFloat(points[i].getAttribute("lng")),
                                parseFloat(points[i].getAttribute("lat")));
           if (i > 0) {
             length += pts[i-1].distanceFrom(pts[i]);
             if (isNaN(length)) { alert("["+i+"] length="+length+" segment="+pts[i-1].distanceFrom(pts[i])) };
           }
           bounds.extend(pts[i]);
           point = pts[parseInt(i/2)];
        }
        // length *= 0.000621371192; // miles/meter 


  if (comp < 1) { 
 colorr = '#FA0505' }

 if (comp > 0 && comp < 25 ) { 
 colorr = '#FFA640' }

 if (comp > 24 && comp < 50) { 
 colorr = '#FFFD91' }

 if (comp > 49 && comp < 75) { 
 colorr = '#E8E400' }

 if (comp > 74 && comp < 100) { 
 colorr = '#BFFFAD' }

 if (comp == 100) { 
 colorr = '#0F8500' }


        var poly = new g.Polyline({
                          map:map,
                          path:pts,
                          strokeColor:colorr,
                          strokeWeight:width,
                          clickable: true
                          });



google.maps.event.addListener(poly,'mouseover', function() {


        this.setOptions({strokeColor: '#690469' });
           this.setOptions({strokeOpacity: 1.0 });
           this.setOptions({strokeWeight: 4 });



  });

     google.maps.event.addListener(poly,'mouseout', function() {


        this.setOptions({strokeColor: colorr });
           this.setOptions({strokeOpacity: 1.0 });
           this.setOptions({strokeWeight: 4 });
  });


    var funcs = [];

function createfunc(i) {
    return function() { 


  google.maps.event.addListener(poly,'click', function(event) {
    mpenc.setContent(html +i);
    mpenc.setPosition(event.latLng);
    mpenc.open(map);
  });



    };
}

for (var i = 0; i < lines.length; i++) {
    funcs[i] = createfunc(i);
}

for (var j = 0; j < lines.length; j++) {
    funcs[j]();                        // and now let's run each one to see
}  







      }
      map.fitBounds(bounds);

    });



}
brio
  • 175
  • 2
  • 5
  • 16
  • You're not saying what specifically is wrong... Check your browser's error console for any errors, and read [JavaScript closure inside loops](http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example) for a detailed explanation of a problem you need to be aware of in `bInfoWindow`. (And indent your code consistently.) – DCoder Mar 31 '13 at 13:18
  • thanks for answer. I saw this post.. But i cant implement this ((.. 3 days i work on this but cant implement (( – brio Mar 31 '13 at 13:20
  • possible duplicate of [Get DATA from xml google maps](http://stackoverflow.com/questions/15697781/get-data-from-xml-google-maps) – geocodezip Mar 31 '13 at 13:47
  • Do not repost questions. That serves you no good. – Antony Mar 31 '13 at 13:54
  • not a dublicate. problem is showing data..not a last data! – brio Mar 31 '13 at 14:01

0 Answers0