本文介绍了检索MySQL点类型的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用类似以下内容的点将经纬度对存储在MySQL中:

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

GeomFromText('POINT(32 -122)')

鉴于这一点,我该如何检索各个X/Y坐标?

Given the point, how do i retrieve the individual X/Y coordinates?

推荐答案

假设您将GeomFromText('POINT(32 -122)')作为MY_POINT列存储在名为MY_TABLE的表中.

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

获取X坐标(在此示例中将返回32):

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

SELECT ST_X(MY_POINT) as latitude FROM MY_TABLE;

获取Y坐标(在本示例中将返回-122):

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

SELECT ST_Y(MY_POINT) as longitude FROM MY_TABLE;

重要:在5.6版之前,请使用X()和Y()代替ST_X()和ST_Y().

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

这篇关于检索MySQL点类型的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 07:56