PostgreSQL纬度经度查询

编程入门 行业动态 更新时间:2024-10-28 03:18:29
本文介绍了PostgreSQL纬度经度查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在PostgreSQL数据库的location表中有latitude和longitude列, 并且我正在尝试使用PostgreSQL函数执行距离查询.

i have latitude and longitude columns in location table in PostgreSQL database, and I am trying to execute distance query with a PostgreSQL function.

我阅读了本手册的这一章:

I read this chapter of the manual:

www.postgresql/docs/current/static/earthdistance.html

但是我想我在那里丢失了一些东西.

but I think I'm missing something there.

我该怎么做?是否有更多示例可用

How should I do that? Are there more examples available

推荐答案

此模块是可选的,并且未安装在默认的PostgreSQL安装中.您必须从contrib目录安装它.

This module is optional and is not installed in the default PostgreSQL instalatlion. You must install it from the contrib directory.

您可以使用以下函数来计算坐标之间的近似距离(以英里为单位):

You can use the following function to calculate the approximate distance between coordinates (in miles):

CREATE OR REPLACE FUNCTION distance(lat1 FLOAT, lon1 FLOAT, lat2 FLOAT, lon2 FLOAT) RETURNS FLOAT AS $$ DECLARE x float = 69.1 * (lat2 - lat1); y float = 69.1 * (lon2 - lon1) * cos(lat1 / 57.3); BEGIN RETURN sqrt(x * x + y * y); END $$ LANGUAGE plpgsql;

更多推荐

PostgreSQL纬度经度查询

本文发布于:2023-10-26 07:30:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529487.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:经度   纬度   PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!