質問

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