Retrieving the coordinates of the MySQL point type

后端 未结 1 1460
灰色年华
灰色年华 2020-12-09 09:29

I\'m storing lat/long pairs in MySQL as a point using something like:

GeomFromText(\'POINT(32 -122)\')

Given the point, how do i retrieve t

相关标签:
1条回答
  • 2020-12-09 09:45

    Let's say you store GeomFromText('POINT(32 -122)') as a column called MY_POINT in a table called MY_TABLE.

    Getting the X coordinate (will return 32 in this example):

    SELECT ST_X(MY_POINT) as latitude FROM MY_TABLE;
    

    Getting the Y coordinate (will return -122 in this example):

    SELECT ST_Y(MY_POINT) as longitude FROM MY_TABLE;
    

    Important: Prior to version 5.6, use X() and Y() instead of ST_X() and ST_Y().

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