Hey guys!
I have a problem I"ve been working on for days and I don"t know what
to do!
I've got an array with addresses. Within the main function initialize
() I take one address after another and try to geocode the address.
For every address the function addAddressToMap() is called. This
function checks the return code and decides what to do. Every path
ends with the incrementation of a counter variable. At the end of the
script I'd like to output the result by alerting all the variables,
but they all have a value of 0 except the addressIndex which correctly
shows 30.
Why? The variables are global they should be accessible and work
correctly. I already tried to alert the counter variables each time
they are incremented. This works fine but at the end they are all 0.
My next attempt was, to output the counter variables individually.
Then I get some values unlike 0, but the output value depends on how
much alerts I have. That can't be! What am I doing wrong? I don't know
any further. Maybe, one of you guys easily sees the fault.
Thanks in advance for your help!

Here you get the script, because at the moment, I'm developing offline
on localhost with xxamp.

<script type="text/javascript">

var map = null;
var addressIndex = 0;
var enter = 0;
var countMarker = 0;
var countErrorQuery = 0;
var countErrorResponse = 0;
var countErrorDifferent = 0;*/
var geocoder = new GClientGeocoder();

var stations = new Array();
stations[0] = "4105, E Willow St, Long Beach, CA";
stations[1] = "4035, Via Oro, Long Beach, CA";
stations[2] = "2367, E Willow St, Long Beach, CA";
stations[3] = "1024, E Willow St, Long Beach, CA";
stations[4] = "69, Corinthian Walk, Long Beach, CA";
stations[5] = "5375, Appian, Long Beach, CA";
stations[6] = "1637, 7th, Long Beach, CA";
stations[7] = "4105, 2nd, Long Beach, CA";
stations[8] = "2345, 2nd, Long Beach, CA";
stations[9] = "Airport, Long Beach, CA";
stations[10] = "2105, 4th, Long Beach, CA";
stations[11] = "347, Anaheim, Long Beach, CA";
stations[12] = "867, Carson, Long Beach, CA";
stations[13] = "1524, E South, Long Beach, CA";
stations[14] = "3015, E South, Long Beach, CA";
stations[15] = "3478, Del Amo, Long Beach, CA";
stations[16] = "637, Atlantic, Long Beach, CA";
stations[17] = "6105, E Spring, Long Beach, CA";
stations[18] = "5047, E Spring, Long Beach, CA";
stations[19] = "1045, E Ocean, Long Beach, CA";
stations[20] = "1478, Del Amo, Long Beach, CA";
stations[21] = "478, Del Amo, Long Beach, CA";
stations[22] = "2478, Del Amo, Long Beach, CA";
stations[23] = "1024, E Roscrans, Long Beach, CA";
stations[24] = "1569, E Compton, Long Beach, CA";
stations[25] = "2375, E Alondra, Long Beach, CA";
stations[26] = "2637, E Roscrans, Long Beach, CA";
stations[27] = "3105, E Compton, Long Beach, CA";
stations[28] = "1145, E Alondra, Long Beach, CA";
stations[29] = "2145, Artesia, Long Beach, CA";

function addAddressToMap(response) {
enter++;
if(!response) {
countErrorResponse++;
}
else {
if(response.Status.code != 200) {
if (response.Status.code == G_GEO_TOO_MANY_QUERIES) {
countErrorQuery++;
//alert(countErrorQuery);
}
else {
//alert("Sorry, '" + response.name + "' seems to be a bad address!");
countErrorDifferent++;
}
}
else {
var place = response.Placemark[0];
var point = new GLatLng(place.Point.coordinates[1],
place.Point.coordinates[0]);
var marker = new GMarker(point);
map.addOverlay(marker);
countMarker++;
}
}
}

function initialize() {
if (GBrowserIsCompatible()) {

enter = 0;
countMarker = 0;
countErrorQuery = 0;
countErrorResponse = 0;
countErrorDifferent = 0;
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(33.8345, -118.212), 12);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.enableScrollWheelZoom();
geocoder = new GClientGeocoder();

//map.addOverlay(new GMarker(new GLatLng(33.8345, -118.212)));

while(addressIndex < stations.length) {
geocoder.getLocations(stations[addressIndex], addAddressToMap);
addressIndex++;
}
alert("entered: " + enter + "nstations added: " + countMarker +
"nerrors:ntErrorsResponse: " + countErrorResponse + "ntErrorsQuery: "
+ countErrorQuery + "ntErrorsDifferent: " + countErrorDifferent +
"naddressindex: " + addressIndex);
}
    }

    </script>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to