I've got som problem setting some values in my js-code. I've tried to figure out what the problem is but still can't find the issue in the code.
It's the mostN, mostE, mostW, mostS values I want to set.
The alert at the end of the code i "Undefined". Why? And How do I fix it? Thx!
var mostN,
mostE,
mostW,
mostS;
for (i = 1; i < opts.markers.length; i += 1) //loops 5 times
{
$geocoder.geocode(
{
address: opts.markers[i].address},
function (result, status)
{
if (status === google.maps.GeocoderStatus.OK)
{
var str = [result[0].geometry.location]; // "(42.456465, -48.74116)"
var realString = str.toString();
var stop = realString.length - 1;
var real = realString.substring(1,stop); // "42.456465, -48.74116"
var arr = real.split(", ");
var lat = arr[0].toString(); // "42.456465"
var lng = arr[1].toString(); // "-48.74116"
if(mostN > lat) { mostN = lat; }
if(mostE < lng) { mostE = lng; }
if(mostW > lng) { mostW = lng; }
if(mostS < lat) { mostS = lat; }
alert(mostN); // returns "Undefined"
}
else
{
if (opts.log) {console.log("Geocode was not successful for the following reason: " + status); }
}
}
);
}