Question

I was searching stackoverflow and got an answer to my question, but when I tried to implement it with my code I got weird errors.

here is the code:

SELECT `zip_code`, (6371 * acos(cos(radians($latitude)) * cos(radians(`lat`)) * cos(radians(`long`) - radians($longitude)) + sin(radians($latitude)) * sin(radians(`lat`)))) AS `distance`
FROM `places`
HAVING `distance` < $within
ORDER BY `distance` ASC
LIMIT 10;

I get the following error:

Incorrect parameter count in the call to native function 'radians'

I use MySQL version 5.1.44

Was it helpful?

Solution

From the links I found, this is usually caused by passing degree arguments to the radians function with commas separating the whole number from the decimal part of the degree value.

53,779 degrees longitude 4,566 degrees latitude

This looks like two arguments (separated by a comma) to the radians function and it throws the error you see.

The solution is to do some on the fly modification to format your degree arguments with period as the separator instead of commas.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top