weralio

Closest segment to point using geometry service..  how to wait for the answers?

Discussion created by weralio on Jan 20, 2013
Situation:
geometry 1: Point
geometry 2: segments  (from an array of segments already returned by the call to the geometry service - buffer function)

I need to loop thru them getting the DISTANCE (again using the GeometryService distance function) just to compare and try to find the closest one... but the call will fire the onDistanceComplete(distance) whenever is done.. how I'm supposed to be waiting for this value efficiently?? just looping while the event is fired?? should I have to use a deferred methodology??

basically trying to make something like this works

for (segm=0; segm = segments.length; segm++)
{
     geom1 = point
     geom2 =  segments[segm]

     HOW I WAIT FORTHIS RETURN?
       geometryService.distance(distParams, function(distance) {
        currDistance= distance});

    //Comparison currentDistance  with minDistance
}

Outcomes