問題描述
我正在使用 Phonegap 和 JQuery 創(chuàng)建一個(gè)移動(dòng)應(yīng)用.
I am creating a mobile app using Phonegap and JQuery.
該應(yīng)用程序收集用戶的經(jīng)緯度并將其存儲(chǔ)在數(shù)據(jù)庫(kù)中(使用 PHP 腳本 - 網(wǎng)絡(luò)服務(wù)),并通過某種算法檢測(cè)是否有流量.我需要的是從數(shù)據(jù)庫(kù)中獲取所有彼此接近的經(jīng)度和緯度值,比如在同一街道/200 米范圍內(nèi).
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.
假設(shè)您在數(shù)據(jù)庫(kù)中有一個(gè)列表,其中 5 lon/lat 彼此靠近(在同一條街道 A 中),3 lon/lat 在某些街道 B 中彼此靠近,而其他一些則隨機(jī)代表用戶在其他街道.誰能告訴我如何檢測(cè)彼此接近的 lon/lat 值?我將這些值作為單獨(dú)的值存儲(chǔ)在 MySQL 數(shù)據(jù)庫(kù)中,即一個(gè)字段表示經(jīng)度,另一個(gè)字段表示緯度.
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.
一旦我獲得彼此靠近的經(jīng)度/緯度,那么我需要找到街道 A 中的用戶和街道 B 中的用戶之間的中心點(diǎn)以標(biāo)記為交通擁堵(基于其他一些檢測(cè)).
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).
推薦答案
您應(yīng)該研究Haversine 公式.請(qǐng)看下圖:
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;
這將返回輸入長(zhǎng)/緯度對(duì) 25 英里范圍內(nèi)的所有記錄.
This will return all records that are within 25 miles of the input long / lat pair.
這篇關(guān)于從數(shù)據(jù)庫(kù)獲取相似的經(jīng)緯度的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!