Hey there
I've a list of addresses that I want to solve, ive tried two things:
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
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
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
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.