문제

I calculate distance between locations using havershine formula.

$distance = (((acos(sin(($fromLat * pi() / 180)) * sin(($toLat * pi( )/ 180)) + cos(($fromLat * pi() / 180)) * cos(($toLat * pi() / 180)) * cos((($fromLon - $toLon) * pi() / 180)))) * 180 / pi()) * 60 * 1.1515);

It works normally, but for some coordinate values it is giving NAN.

Values it gives NAN for are

fromLat : 22.303894
fromLon : 70.802162
toLat : 22.303894
toLon : 70.802162
도움이 되었습니까?

해결책

You're comparing the same coordinates. The acos function is being asked to calculate the arc cosine of 1, which fails. You will want to check if the coordinates are identical before passing it through the function. Also, if you're not getting a number, the result is probably no distance.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top