Titanium Appcelerator Quickie: ForwardGeocoder callback with looping - Clearly Innovative | Web and Mobile DevelopmentClearly Innovative | Web and Mobile Development

Need Help With A Mobile Development Project?

The main challenge here is understanding how callbacks work and that the forward geocode lookup is asynchronous.

If you try and just call forwardGeoCode repeatedly and in succession, it simply will not work as you expected.

To solve the problem we use simple recursion where we call the method once to process the address and then wait until it is done before we call the rest of the items in the queue/list.

See code below…

In the example above, I use recursion, but I could have also used event based programming; in that scenario I would fire off the initial event to start processing the addressQueue and then when an item has finished processing, just fire the event again

Need Help With A Mobile Development Project?