在给定的半径内找到附近的位置

时间:2021-04-12 02:11:08

I have stored latitude and longitude for different interesting places in my database. Whenever a user clicks into any of the interesting places, the show page displays details of the location, along with a google map with a marker pointing at it.

我已经在我的数据库中为不同有趣的地方存储了纬度和经度。每当用户点击任何有趣的地方,显示页面就会显示该位置的详细信息,以及带有指向它的标记的谷歌地图。

Now I have been trying to implement a button to "Show nearby places", along with a drop-down for ranges (eg. 50km, 100km, 150km), but could not figure out how to do it.

现在,我一直在尝试实现一个按钮来“显示附近的位置”,以及一个用于范围的下拉列表。50km, 100km, 150km,但不知道怎么做。

I was wondering how to find the neighboring places within a given range from a selected location, using the latitudes and longitudes I have in my database.

我想知道如何使用我数据库中的纬度和经度,从选定的位置找到给定范围内的相邻位置。

3 个解决方案

#1


3  

You should use geocoder, it provides builtin methods like:

您应该使用geocoder,它提供了诸如:

Venue.near([40.71, 100.23], 20)    # venues within 20 miles of a point

#2


1  

If you need to be precise - you need to keep in mind Earth's shape - it is not a plane. So, choose your accuracy level (simple sphere, WGS84) and write some math for it. And what database do you use? Some of them can operate with spartial inedxes which may be very useful.

如果你需要精确——你需要记住地球的形状——它不是一个平面。所以,选择你的精度等级(简单的球面,WGS84)并为它写一些数学。你用什么数据库?它们中的一些可以使用少量的inedxes是非常有用的。

#3


0  

for an easy - not accurate, but fast approach look here on SO small distance

为了一个简单-不准确,但快速的方法看这里,在这么小的距离

it is using a simple technical logic the fits many problems in real world, but it is fast but not intended do be accurate

它使用的是一种简单的技术逻辑,适用于现实世界中的许多问题,但是它是快速的,但并不打算是准确的

#1


3  

You should use geocoder, it provides builtin methods like:

您应该使用geocoder,它提供了诸如:

Venue.near([40.71, 100.23], 20)    # venues within 20 miles of a point

#2


1  

If you need to be precise - you need to keep in mind Earth's shape - it is not a plane. So, choose your accuracy level (simple sphere, WGS84) and write some math for it. And what database do you use? Some of them can operate with spartial inedxes which may be very useful.

如果你需要精确——你需要记住地球的形状——它不是一个平面。所以,选择你的精度等级(简单的球面,WGS84)并为它写一些数学。你用什么数据库?它们中的一些可以使用少量的inedxes是非常有用的。

#3


0  

for an easy - not accurate, but fast approach look here on SO small distance

为了一个简单-不准确,但快速的方法看这里,在这么小的距离

it is using a simple technical logic the fits many problems in real world, but it is fast but not intended do be accurate

它使用的是一种简单的技术逻辑,适用于现实世界中的许多问题,但是它是快速的,但并不打算是准确的