mysql经纬度计算距离,官方支持方法

先看下官方文档

  • ST_Distance_Sphere(g1, g2 [, radius])

    Returns the mimimum spherical distance between two points and/or multipoints on a sphere, in meters, or NULL if any geometry argument is NULL or empty.

    Calculations use a spherical earth and a configurable radius. The optional radius argument should be given in meters. If omitted, the default radius is 6,370,986 meters. An ER_WRONG_ARGUMENTS error occurs if the radius argument is present but not positive.

    The geometry arguments should consist of points that specify (longitude, latitude) coordinate values:

    Supported argument combinations are (PointPoint), (PointMultiPoint), and (MultiPointPoint). An ER_GIS_UNSUPPORTED_ARGUMENT error occurs for other combinations.

    If any geometry argument is not a syntactically well-formed geometry byte string, an ER_GIS_INVALID_DATA error occurs.

    mysql> SET @pt1 = ST_GeomFromText('POINT(0 0)');
    mysql> SET @pt2 = ST_GeomFromText('POINT(180 0)');
    mysql> SELECT ST_Distance_Sphere(@pt1, @pt2);
    +--------------------------------+
    | ST_Distance_Sphere(@pt1, @pt2) |
    +--------------------------------+
    |             20015042.813723423 |
    +--------------------------------+
    • Longitude and latitude are the first and second coordinates of the point, respectively.

    • Both coordinates are in degrees.

    • Longitude values must be in the range (-180, 180]. Positive values are east of the prime meridian.

    • Latitude values must be in the range [-90, 90]. Positive values are north of the equator.

直接上使用方法

此方法时mysql官方支持函数

select
ST_Distance_Sphere(point (目标经度,目标纬度),point(经度,纬度)) distance
from table 
举个例子

select  ST_Distance_Sphere(point (113.6350421, 34.7950488),point(113.6051975,34.7418565)) AS distance from demo_table

可以参考官方文档

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值