简体   繁体   English

我应该如何计算一个人是否在使用地理位置的商店50米范围内?

[英]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。

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.

相关问题 Javascript 定位到 10 米以内 - Javascript Geolocation to within 10 meters 如何使用力矩js计算人员的年龄? - how to calculate the age of person using moment js? 计算一个范围内有多少项目 - Calculate how many items within a range 通过地理位置计算哪个商店最接近用户 - Calculate which store is closest to user through geolocation 如何计算此人获得的等级 - How to calculate the grade the person received 在我的 userinfo 命令中,我应该怎么做,我不必使用此人的 ID 并 ping 他们。 它将显示使用 cmd 的人的信息 - In my userinfo command how should i do that I don’t have to use the ID of the person and ping them. It will show the info of the person using the cmd 如何在Google App Engine上存储HTML 5地理位置数据? - How do I store HTML 5 Geolocation Data on Google App Engine? 如何使用他输入的 DOB 存储人的年龄但它不起作用 - How to store the age of the person using his DOB entered but it's not working 如何查找数组中的至少 3 个元素是否在 JavaScript 的 50 到 99 范围内? - How to find if at least 3 elements within an array are within range of 50 to 99 in JavaScript? 如何查找数组中的任何元素是否在 JavaScript 的 50 到 99 之间? - How to find if any of elements within an array are within range between 50 and 99 in JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM