0

I'm trying to calculate the distance from a lat, lon using haversine formula. For some reason this only works in the northern hemisphere and I'm suspecting its because of the abs. Once I remove the absolute value, the code works fine. So I was just wondering what is the purpose of using it?

'(3956 * 2 * ASIN(SQRT( POWER(SIN((' . $latitude . ' - abs(r.latitude)) * 
pi()/180 / 2),2) + COS(' . $latitude . ' * pi()/180 ) * COS(abs(r.latitude) *  
pi()/180) * POWER(SIN((' . $longitude . '-r.longitude) *  pi()/180 / 2), 2) ))) 
< ' . $radius;
Henrique Barcelos
  • 7,670
  • 1
  • 41
  • 66
dudemanbearpig
  • 1,264
  • 3
  • 12
  • 19
  • Latitude 0 is the equador, if you have non-zero latitude, you must specify if it's north or south. I'd guess that the convention is that north latitudes are positive and south ones are negative, so, you CAN'T have and `abs` in there... – Henrique Barcelos Nov 12 '13 at 16:54
  • @HenriqueBarcelos Thats what I was thinking too, but according to http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL (look at slide 8), you need the absolute value – dudemanbearpig Nov 12 '13 at 16:57
  • There's no way to know wether you are north or south without a signed latitude because `SIN` is an odd function, that means: `SIN(-x) = -SIN(x)` – Henrique Barcelos Nov 12 '13 at 17:00

0 Answers0