I'm trying to create an XML formatted output in a textarea but have run into a asynch problems:
$(document).ready(function() {
var geocoder;
geocoder = new google.maps.Geocoder();
$('#xmloutput').val('<?xml version="1.0" encoding="UTF-8"?>\n<parent>\n');
var addresslist = 'one\ntwo\nthree';
var addlines = addresslist.split('\n');
$.each(addlines, function(name, value) {
geocoder.geocode( { 'address': value}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
$('#xmloutput').val($('#xmloutput').val()+'<node>'+value+'</node>\n');
}
});
});
$('#xmloutput').val($('#xmloutput').val()+'</parent>');
});
I want this output:
<?xml version="1.0" encoding="UTF-8"?>
<parent>
<node>one</node>
<node>two</node>
<node>three</node>
</parent>
But I get this output because the geocoding takes a while...
<?xml version="1.0" encoding="UTF-8"?>
<parent>
</parent><node>one</node>
<node>two</node>
<node>three</node>
I've seen a lot of similar posts and the fix seemes to be chaining or callback, but I've not managed to get anything working yet. How should I approach this?
Thanks! Ben