2017-07-13 57 views
-1

我有很多用户用他们的经纬度,长在与mongodb的节点js服务器。如何从谷歌地图搜索特定区域的用户?

现在我要进入一个位置说纽约。并且它会通过地理编码API转换为经纬度,并在范围内搜索10英里半径。现在我想知道哪些用户在该区域内匹配。我如何做这部分?

对不起,英语不好。

+0

所以基本上你想知道基于lat和lng的面积? –

+0

您是否考虑在地图上根据人物的位置放置标记? –

+0

@ZiyaERKOC是的,我做到了。我更新了描述。请检查 –

回答

0

我假设你通过地理编码获得了纽约的位置。由于您拥有用户的坐标,因此您可以通过简单的几何和数学技巧将这些位置与纽约的位置进行比较。
userLat为用户的纬度,userLng为用户的经度。并且yorkLatyorkLng是纽约的坐标。你基本上可以建立如下公式:

locationDiff = Math.sqrt(Math.pow(yorkLng - userLng, 2) + Math.pow(yorkLat - userLat, 2) 
//You could modify inside the if condition to make sure they both have the same unit 
if(locationDiff <= 100000){ 
    //This user is within the circle whose center is New York location and radius you provided 
}