[英]How should I calculate if a person is within 50 meters range of a store using geolocation?
I have the store's latitude and longitude saved in database, and the user's geolocation is obtained with javascript from his mobile browser. 我将商店的纬度和经度保存在数据库中,用户的地理定位是通过他的移动浏览器中的javascript获得的。
How should I calculate if the user's distance from the store is within 50m? 如何计算用户与商店的距离是否在50米以内?
Maybe (x1-x2)**2+(y1-y2)**2 < a certain threshold
? 也许
(x1-x2)**2+(y1-y2)**2 < a certain threshold
?
ps This is like foursquare checkin. ps这就像foursquare checkin。
sqrt((x2-x1)^2 + (y2-y1)^2) < 50
http://www.mathwarehouse.com/algebra/distance_formula/index.php
This site ( Calculate distance, bearing and more between Latitude/Longitude points ) provide a good explanation and calculation formula. 此站点( 计算纬度/经度点之间的距离,方位和更多 )提供了一个很好的解释和计算公式。 You may want to check it out.
你可能想看一下。
Here is an example using javascript
: 以下是使用
javascript
的示例:
function calcDistance(p1, p2){
return Math.sqrt(Math.pow(p2.x-p1.x, 2) + Math.pow(p2.y-p1.y, 2));
}
var store = { x:21, y:36 };
var device = { x:11, y:56 };
console.log( calcDistance(store, device) );
console.log( "Within 50m ? " + (calcDistance(store, device) < 50) );
Result: 结果:
22.360679774997898
Within 50m ? true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.