mborr

Variables between functions

Discussion created by mborr on Dec 1, 2011
Latest reply on Dec 5, 2011 by mborr
Hi, this may be stupidly easy, but I cannot pass a variable (geom) to another function. I defined geom globally, and it will display when I call the "innerHTML" within its own function, but when I put it in function gpit, it comes back undefined. I need to use geom to do other things within gpit, but can't seem to see it. Any ideas why I cannot do this?

var geom;

  function showResults(candidates, result) {
        var candidate;
        var symbol = new esri.symbol.SimpleMarkerSymbol();
        var infoTemplate = new esri.InfoTemplate("Location","Address: ${address}<br />Score: ${score}<br />Source locator: ${locatorName}");

        symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE);
        symbol.setColor(new dojo.Color([153,0,51,0.75]));

        
       
        dojo.every(candidates,function(candidate, geom){
          console.log(candidate.score);
          if (candidate.score > 80) {
            console.log(candidate.location);
            var attributes = { address: candidate.address, score:candidate.score, locatorName:candidate.attributes.Loc_name };  
            var geom = candidate.location;
            var graphic = new esri.Graphic(geom, symbol, attributes, infoTemplate);
            //add a graphic to the map at the geocoded location
            map.graphics.add(graphic);
            //add a text symbol to the map listing the location of the matched address.
            var displayText = candidate.address;
            var font = new esri.symbol.Font("16pt",esri.symbol.Font.STYLE_NORMAL, esri.symbol.Font.VARIANT_NORMAL,esri.symbol.Font.WEIGHT_BOLD,"Helvetica");
           
            var textSymbol = new esri.symbol.TextSymbol(displayText,font,new dojo.Color("#666633"));
            textSymbol.setOffset(0,8);
            map.graphics.add(new esri.Graphic(geom, textSymbol));
            return false; //break out of loop after one candidate with score greater  than 80 is found.
   
          }
        });
 
        if(geom !== undefined){
          map.centerAndZoom(geom,12);
        }
   
  
      }
     function gpit(geom){
   
   dojo.byId("a").innerHTML = geom.x;
  };

Outcomes