这是一个较旧的问题,但我注意到所有答案都是错误的(至少在2019年),纬度和经度必须相反
正确应该是:POINT(longitude,latitude)
Mysql 5.6及以上版本可使用:
Update myTable
Set coordinates = POINT(longitude, latitude);
如果我们尝试像这样:
SELECT ST_Distance_Sphere(
POINT(13.1500000,99.9666700),
POINT(48.861105, 120.335337)
);
出现错误:
错误 1210 (HY000):st_distance_sphere的参数不正确
因为我在答案中使用了像POINT(latitude, longitude)
这样的代码。
但是,如果我们尝试使用POINT(longitude,latitude)
:
SELECT ST_Distance_Sphere(
POINT(99.9666700, 13.1500000),
POINT(120.335337, 48.861105)
);
结果是:
+
| ST_Distance_Sphere(
POINT(99.9666700, 13.1500000),
POINT(120.335337, 48.861105)
) |
+
| 4389299.754585881 |
+
1 row in set (0.00 sec)