在MySQL表我如何查询(如纬度和长期保存),其这是最近的位置,以inputed位置(经纬度和长)? [英] How can i query in mysql-table(where lat and long stored) that which are the nearest location to inputed location(lat and long)?

查看:257
本文介绍了在MySQL表我如何查询(如纬度和长期保存),其这是最近的位置,以inputed位置(经纬度和长)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android的应用程序。在此应用程序的用户在这个应用程序进行注册。随着注册的GPS位置(经纬度和长)将在数据库表中存储与用户信息。在这个程序,我想添加一个功能,那就是搜索人谁是在根。用户可以输入起点和终点(如:孟买到德里)。而这两点之间的每一个民族​​要被发现。

I want to make an application in android. In this app user have to register in this app. With the registration the gps location(lat and long) will store in database table with user info. In this app i want to add a functionality that is "Search People who are in Root". User can input starting point and ending point(like : Mumbai to Delhi). And every peoples between this two point want to be found.

例如:用户A已经新近在此应用程序注册。用户A的GPS定位就像土地增值税= 20.234554长= 56.21455255。现在,他将投入二点像孟买到德里,然后点击搜索按钮。现在我想在数据库中查询,每一个民族​​的信息已经存储。我想在数据库中查询该选择位置(表)*孟买所在的人民德里

For Example : User-A have newly registered in this app. User-A's gps location is like lat = 20.234554 and long = 56.21455255. Now he will input two point like mumbai to delhi and click search button. Now i want to query in the database where every peoples information has been already stored. I want to query in database that "Select * from Location(Table) where peoples between mumbai to delhi"

数据库表位置有四个字段id,纬度,长和城市名。现在我想上面的查询的数据库在那里我能找到的人就是这两种输入的地缘点之间。

Database table "locations" has four field id, lat, long and cityname. Now i want the above query on the database where i can find the people those are between the two inputted geo points.

希望我已经解释清楚,你明白我想要实现只是,我想只是搜索这是从与输入的位置(经纬度和长)数据库表中的附近位置(经纬度和长)。

Hope i have explained well that you understand what i want to achieve is only that i want to just search which are the nearby locations(lat and long) from the database table with inputted location(lat and long).

推荐答案

我会建议一些条件可以被索引,以限制你的位置。你可以做到这一点很容易,你可能不希望列出某人从美国到有人在巴黎最近的位置。

I would suggest to limit your location by some conditions which can be indexed. You can do that easily as you probably don't want to list somebody from the US to somebody in Paris as nearest location.

只需在RustamIS一点修改查询可以消除大部分不相关的位置。

With just a bit modification on RustamIS query you can eliminate the most of the irrelevant locations.

select * from gps_location_table t 
where
    t.x between 20.134554 and 20.334554 and t.y between 56.11455255 and 56.31455255
order by 
    sqrt((t.x - 20.234554)*(t.x - 20.234554) + (t.y - 56.21455255)*(t.y - 56.21455255)
desc

所以,你定义要寻找最近的人一个矩形。

So you defined a rectangle where you want to look for the nearest people.

这篇关于在MySQL表我如何查询(如纬度和长期保存),其这是最近的位置,以inputed位置(经纬度和长)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆