What is the correct order when setting a POINT in MySQL?
Even the answers in SO questions differ on this: Moving lat/lon text columns into a 'point' type column
Is it
POINT(lat lon)
or
POINT(lon lat)
As far, as i see it, it should be the first version (lat lon) as the POINT takes as params x and y, but i was not able to find an definite evidence.
as one can see here https://stackoverflow.com/a/5757054/1393681 the order is (lon lat).
lon is basicly the y axis and lat the x if i look at my globe, but the lon's are traveling along the x axis and the lat's along the y axis so i think thats the reason why you use (lon lat)
Despite that, if you stay consistent in your application it shoudn't matter if the world is flipped inside your db ;-)
Seems like lat lon
to me. You can check this from your mysql shell:
mysql> SELECT ST_ASTEXT(coords), ST_LONGITUDE(coords), ST_LATITUDE(coords) FROM table;
+----------------------------+-----------------------+----------------------+
| ST_ASTEXT(coords) | ST_LONGITUDE(coords) | ST_LATITUDE(coords) |
+----------------------------+-----------------------+----------------------+
| POINT(33.520571 -18.20072) | -18.20072 | 33.520571 |
+----------------------------+-----------------------+----------------------+
Note: SRID 4326 used.
See also: https://dev.mysql.com/doc/refman/8.0/en/gis-point-property-functions.html#function_st-latitude
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With