Lon/Lat Order when using spatial POINT type with MySQL

前端 未结 3 636
隐瞒了意图╮
隐瞒了意图╮ 2020-12-20 17:13

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

相关标签:
3条回答
  • 2020-12-20 17:19

    Technically it does not matter. You are storing into the x and y coordinates of a point. You just have to read them the same way you write them.

    If you care about a "proper way" I can only refer to the fact that Google Maps API creates coortinates using

    var location = new google.maps.LatLng(lat, lng);
    

    and in school you also learn about "latitude and logintude", not the other way arround.

    Still, technically it really doesn't metter which way you store them. Just make sure that you use the same convention when you read them back.

    0 讨论(0)
  • 2020-12-20 17:25

    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

    0 讨论(0)
  • 2020-12-20 17:34

    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 ;-)

    0 讨论(0)
提交回复
热议问题