[GIS] MySQL normalizing points with latitude > 90

mysql-spatial

Facing very strange problem, I've points table for storing location of users in location(POINT) column. Problem with st_distance_sphere function where I've stored some specific location.

update points set location = point(30.492039, 76.587216) WHERE id = 1;

its Working fine but when I've changed lat,lng to

update points set location = point(52.051503, 113.471190) WHERE id = 1;

its called:

Incorrect arguments to st_distance_sphere

Table:

CREATE TABLE `points` (
  `id` int(10) NOT NULL,
  `name` varchar(45) ,
  `location` point,
  PRIMARY KEY (`id`),
) 

Query:

    SELECT id,ST_Distance_Sphere(point(52.408089, 113.489844),location)/1000 
AS distance FROM points HAVING distance < 100; 

Best Answer

Looks like the POINT constructor format is POINT(longitude, latitude), this is, longitude first, latitude second.

MySQL wont complain if you save a point like point(52.408089, 113.489844) on a table field, but it won't be able to calculate distances since that point has a latitude greater than 90 degrees.

Related Question