the following test is basically ~1000 math operations and works fine on most PC and android browsers, and iOS 4.x. On iOS5 safari (iPhone 4 and iPad 2) we get "JavaScript: Error undefined JavaScript execution exceeded timeout". Any help greatly appreciated thanks.
/** Converts numeric degrees to radians */
if (typeof (Number.prototype.toRad) === "undefined") {
Number.prototype.toRad = function () {
return this * Math.PI / 180;
}
}
function gc(lat1, lon1, lat2, lon2) {
// returns the distance in km between a pair of latitude and longitudes
var R = 6371; // km
var dLat = (lat2 - lat1).toRad();
var dLon = (lon2 - lon1).toRad();
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var d = R * c;
return d;
}
function test() {
var d1 = new Date();
var lat1, lon1, lat2, lon2;
lat1 = -36;
lon1 = 174;
lat2 = lat1;
lon2 = lon1;
while (lat2 > -37) {
lat2 = lat2 - 0.001;
var stest = "lat1=" + lat1 + ",lon1=" + lon1 + ",lat2=" + lat2 + ",lon2=" + lon2 + "=" + gc(lat1, lon1, lat2, lon2);
}
var d2 = new Date();
var stest = (d2.getTime() - d1.getTime()) / 1000.0 + "s";
$("#lblTest").html(stest + "<BR/>" + $("#lblTest").html());
}