mysqlspatial-querysrid

MySQL 8 st_distance_sphere gives different values for different SRID


When, I run (SRID = 4326)

Select st_distance_sphere( ST_GeomFromText( 'point(-51 -23)',4326), ST_GeomFromText('Point(-51.4264 -23.4158)',4326))/1000 as distance;

I get

'55.55951760685804'.

SRID 4326

But, when, I run (SRID = 0)

Select st_distance_sphere( ST_GeomFromText( 'point(-51 -23)'), ST_GeomFromText( 'Point(-51.4264 -23.4158)'))/1000 as distance;

srid 0

I get 63.5340251950123, which looks like to be the right distance value. But, I thought that function do not change its result by changing the SRID of the points. Even worse when its return wrong result when I set the SRID. Someone can help me understand what going on here ? =) By the way, I am using Mysql 8.


Solution

  • Finally, I found the answer here. The problem is that when change from SRID 0 to 4326, the lat long order to create the point must change. I did not know that. I think this is really confused and not well documented. Anyway, after change the lat long order in 4326 case, I got the right distance value.