問題描述
我正在使用 Phonegap 和 JQuery 創建一個移動應用.
I am creating a mobile app using Phonegap and JQuery.
該應用程序收集用戶的經緯度并將其存儲在數據庫中(使用 PHP 腳本 - 網絡服務),并通過某種算法檢測是否有流量.我需要的是從數據庫中獲取所有彼此接近的經度和緯度值,比如在同一街道/200 米范圍內.
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/lat 在某些街道 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.
一旦我獲得彼此靠近的經度/緯度,那么我需要找到街道 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;
這將返回輸入長/緯度對 25 英里范圍內的所有記錄.
This will return all records that are within 25 miles of the input long / lat pair.
這篇關于從數據庫獲取相似的經緯度的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!