Weird Great Circle Distance calculation

I have some problems with a great circle distance calculation using a map.

Context: http://airports.palzkill.de/search/

The map is supposed to work as a great circle distance search map - you move the circles center marker or the radius marker, and the circle gets smaller or larger. For debug purposes, the boxes title field shows the calculated distance in km.

This only works fine as long as the circle center is close to 0/0, and the radius marker is not too far away from it. The more you move either of the markers to "extremes", the more off some tangent the whole thing goes and produces nothing but crap.

This is the code used for calculating the updates, you can also find the entire code in the JS file js.js, lines 146 to 184:

function searchmapupdate()
{   
rad_lat_radiuspos = (circleradiusmarker.getPosition().lat()*Math.PI/180);
rad_lon_radiuspos = (circleradiusmarker.getPosition().lng()*Math.PI/180);
rad_lat_circlecenter = (circlecentermarker.getPosition().lat()*Math.PI/180);
rad_lon_circlecenter = (circlecentermarker.getPosition().lng()*Math.PI/180);

circleradiusvar = Math.acos(Math.sin(rad_lat_circlecenter)*Math.sin(rad_lat_radiuspos)+Math.cos(rad_lat_circlecenter)*Math.cos(rad_lon_radiuspos)*Math.cos(rad_lon_circlecenter-rad_lon_radiuspos))*6371.01*1000;

if (isNaN(circleradiusvar)==false) circle.setOptions({center:circlecentermarker.getPosition(), radius:circleradiusvar});

document.getElementById("mapsearchhead").innerHTML = Math.round(circleradiusvar/1000);
}

Since the whole thing does calculate some correct output I assume the math itself is not totally wrong, I guess there is just some "correctional" stuff missing? К сожалению, я совершенно не разбираюсь в тригонометрии, поэтому я не имею ни малейшего понятия, что здесь может быть не так, и даже где начать поиск идей, как это исправить.

Марко

PS: Я знаю это из-за сферической формы. природа проекции, все это должно действовать "противоинтуитивно" вокруг полюсов. Но это на самом деле не объясняет, что происходит, когда вы перемещаете оба маркера близко к линии даты вокруг экватора (0/179, 0 / -179).

5
задан Marco P. 28 October 2010 в 17:13
поделиться