Select to view content in your preferred language

Locator not solving in right order

3592
11
07-08-2015 05:18 PM
HamishKingsbury1
Occasional Contributor

Hey there

I've a list of addresses that I want to solve, ive tried two things:

  1. using locator.addressToLocations - I iterate through the list of addresses. This will solve the results, but sometimes they will not be in the same order as they were in the list - this is an issue.
  2. using locator.addressessToLocations - this will simply not solve. I can't even get it to work in the REST end point.

I'd like to try to fix the issues with my first attempt as i also need to do some other things during the iteration. Below is my code:

    for (i in depotLocs) {
        console.log(i)
        var locator = new esri.tasks.Locator(this.config.geoCoder);
        console.log("A")
        locator.outSpatialReference = sRef;
        console.log("B")
        var optionsFrom = {
            address: { "SingleLine": depotLocs },
            outFields: ["Loc_name"]
        };
     
        locator.addressToLocations(optionsFrom,function(candidate){
            var r = candidate;
            facilitiesGraphicsLayer.add(new Graphic(new Point(r[0].location.x,r[0].location.y,sRef)));
            depotGraphic.push(new Graphic(new Point(r[0].location.x,r[0].location.y,sRef)));
            console.log(i)
            console.log(r[0].location.x)
            console.log(r[0].location.y)
            });

Does anyone have a possible solution to it being solved out of order? it is a bit of pain as it doesn't consistently happen.

Cheers

Hamish

Tags (1)
0 Kudos
11 Replies
HamishKingsbury1
Occasional Contributor

I'm fairly confident that the issue is with the code I put in my first post. Here is a screenshot of the console when the tasks are called

issue.png

The addresses have been called from top to bottom (they basically appear in the console simultaneously) but looking at the input parameters they are in the right order. What i think the problem is is that the solve times are different. The last one is being solved second (looking at the solve/return time - and I have confirmed this later down the track when I needed to use the x/y locations of the addresses in order) and is therefore being added before the second and third address

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Hamish,

   If there is only a couple of addresses that you are locating then you could just set the code up to not process the next until the last on is done. But really the addressesToLocations is the proper way as it will maintain the order.

0 Kudos