On my page I'm using MaxMind to populate a users long/lat.
I'm also using a script (containing the haversine formula) to take the users long/lat and assign a distance parameter to an object that relates to a store location.
Once the distance has been stored I want to run the following loop
for(i=0; i<cities.length; i++){
var newLat = cities[i].lat;
var newLon = cities[i].lon;
getDistanceFromLatLonInKm(userLat,userLon,newLat,newLon);
var lowest = 1000
if(cities[i].distance< lowest){lowest = cities[i].distance}
}
cities.sort(function(a, b) {
return a.distance - b.distance;
})[0]
var div = document.getElementById('test');
if(cities[0].fax == null){
div.innerHTML = div.innerHTML + cities[0].street + '<br />' + cities[0].city + '<br />' + cities[0].postal + '<br /><b>Phone:</b>' + cities[0].phone;
}else{div.innerHTML = div.innerHTML + cities[0].street + '<br />' + cities[0].city + '<br />' + cities[0].postal + '<br /><b>Phone:</b>' + cities[0].phone + '<br /><b>Fax:</b>' + cities[0].fax;
}
The only thing is that since there's a delay on the coordinates showing up, the loop can't run right away. How can I run this loop after the coordinates are populated?