如何从MySQL中选择经度,纬度的特定位置?

编程入门 行业动态 更新时间:2024-10-26 22:25:36
本文介绍了如何从MySQL中选择经度,纬度的特定位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我试图获得特定位置的经度和纬度。其实我在mysql表中有一些记录(经度和纬度)。现在我想从表格中获得经度和纬度,它应该有500米左右的经度。请查看代码,我希望你能理解我的问题。 Mysql Location Table

------------------------------------- id |经度|纬度 ------------------------------------- 1 | 25.058036 | 55.133467 ------------------------------------- 2 | 25.056986 | 55.135755 ------------------------------------- 3 | 25.059163 | 55.135616 ------------------------------------- 4 | 25.056860 | 55.132515 ------------------------------------- 5 | 25.055683 | 55.134792

我想得到那些距离应该在500米左右的经度,纬度( 25.057550,55.134729 )。

$ user_long = $ _REQUEST ['user_long']; // 25.057550 $ user_lat = $ _REQUEST ['user_lat']; // 55.134729 从...所在的位置选择*(取500米附近的记录)

我已经搜索过它,并找到一些很好的展示 haversine公式答案和谷歌地图与Php / Mysql ,但我没有得到如何开发这种功能。我知道这个问题可能是愚蠢的,因为我没有添加我的代码,但相信我,我不知道我该怎么做,从哪里开始功能。我会很感激,如果有人引导我关于这个功能。

谢谢

解决方案

((19.286558 - 纬度)* pi()/ 180/2),2)+ COS ()/ 180) * COS(纬度* pi()/ 180)* POWER(SIN(( - 99.612494-经度)* pi()/ 180/2),2))) as距离距表<距离< 10 ORDER BY距离;

这会给你10公里范围内的记录。 在子句中修改500米的查询。

I'm trying to get the longitude and latitude around specific location. Actually I have some records (longitude and latitude) in mysql table. Now i want tofetch those longitude and latitude from table which should have around 500 meter of specific longitude. Please view the code, i hope you will understand my question.

Mysql Location Table

------------------------------------- id | longitude | latitude ------------------------------------- 1 | 25.058036 | 55.133467 ------------------------------------- 2 | 25.056986 | 55.135755 ------------------------------------- 3 | 25.059163 | 55.135616 ------------------------------------- 4 | 25.056860 | 55.132515 ------------------------------------- 5 | 25.055683 | 55.134792

I want to get those longitude, latitude which distance should have around 500 meters of specific (25.057550, 55.134729).

$user_long= $_REQUEST['user_long']; // 25.057550 $user_lat= $_REQUEST['user_lat']; // 55.134729 Select * from location where .... (fetch record around 500 meters)

I have searched about it and find some well expnained haversine formula answer and Google Map With Php/Mysql but i did not got how can i develop this kind of functionality. I know this question may be stupid for someone because i'm not adding my code, but trust me i don't know how can i do it and from where i should start functionality. I will appreciate if someone guide me regarding this functionality.

Thank You

解决方案

SELECT *,3956*2*ASIN(SQRT(POWER(SIN((19.286558 - latitude)*pi()/180/2),2)+COS(19.286558 * pi()/180) *COS(latitude * pi()/180)*POWER(SIN((-99.612494 -longitude)* pi()/180/2),2))) as distance FROM table having distance < 10 ORDER BY distance;

This will give you records within 10 Km range. modify query for 500 meters in having clause.

更多推荐

如何从MySQL中选择经度,纬度的特定位置?

本文发布于:2023-10-08 03:07:31,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:经度   纬度   位置   MySQL

发布评论

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

>www.elefans.com

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