从数据库获取类似的经度和纬度 [英] Getting similar longitude and latitude from database

查看:133
本文介绍了从数据库获取类似的经度和纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Phonegap和JQuery创建了一个移动应用程序。

I am creating a mobile app using Phonegap and JQuery.

应用程序收集用户的经度和纬度,并将它们存储在数据库中(使用PHP脚本 - Web服务),并且使用一些算法检测是否存在业务。我需要的是从数据库中获取所有的经度和纬度值,它们彼此接近,例如在同一条街道/ 200m范围内。

The app collects the longitude and latitude of users and stores them in a database (using a PHP script - web service), and with some algorithm it detects whether there is traffic or not. What I need is to grab all the longitude and latitude values from the database which are close to each other, say in the same street/200m range.

假设你在数据库中有一个5 lon / lat的列表,它们在彼此附近(在同一条街道A),3 lon /其他在某些街道B,和其他一些代表用户随机在其他街道。任何人都能告诉我怎样才能检测到彼此相邻的Lon / lat值?我将它们作为单独的值存储在MySQL数据库中,即一个字段用于经度,另一个用于纬度。

Lets say you have a list in the database with 5 lon/lat which are near each other (in the same street A), 3 lon/lat which are near each other in some Street B, and some other representing users randomly in other streets. Can anyone tell me how I can detect the lon/lat values that are near each other? The values I am storing them as separate values in the MySQL database, ie one field for longitude and another for latitude.

一旦我获得了lon /其他,那么我需要找到街道A中的用户之间的中心点,以及街道B中的用户标记为交通拥堵(基于一些其他检测)。

Once I obtain the lon/lat which are near each other, then I would need to find the center point between the users in street A, and users in street B to mark as a traffic congestion (based on some other detections).

推荐答案

你应该看看Haversine公式。

You should look into the Haversine formula. Please see below:

SELECT id, (3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance 
FROM markers 
HAVING distance < 25 
ORDER BY distance;

这将返回输入long / lat对25英里内的所有记录。

This will return all records that are within 25 miles of the input long / lat pair.

这篇关于从数据库获取类似的经度和纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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