我应该如何使“靠近”......“附近”变得更容易?
我想在我的搜索字段中添加一个功能。 因此,您可以写“接近:哥本哈根”(示例)。
然后应该在哥本哈根周围/内部(哥本哈根是丹麦的首都)5公里范围内,获取其中的地址,并将它们显示为结果。
因此,它会获取所有地址,检查它们是否在周围5公里范围内哥本哈根,然后展示那些。
这可以吗?如果没有,有什么类似的方法吗?我应该调查什么?
I would like to make add a feature to my search field.
So you can write Close to: Copenhagen (example).
It should then take like 5 km range around /inside Copenhagen (copenhagen is capital of denmark), and get the addresses that are within, and show them as results..
So it takes all addresses, checks if they are within 5 km range around copenhagen and then display those that are.
Is this possible to do? If not, any simliar ways to do this? What should i look into?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
例如,您可以使用 Google Maps API 来地理编码 将位置(搜索词和地址)的文本描述转换为 GPS 坐标位置。然后,您检查数据库中的哪些位置在搜索词位置的范围内。不过,使用该 API 的条款和条件要求您使用地理编码结果来显示 Google 地图。
然而,有效地确定“在范围内”可能很棘手,您通常需要一个支持 GIS 的数据库来为您进行计算。在任何数据库上都很容易实现的一种黑客捷径是在搜索词位置的北、东、南、西 5 公里(或任何你想要的距离)处取点,然后查找纬度和经度在最小值之间的地址。以及给您的最大纬度和经度。 此页面列出了所需的公式。 (如果搜索区域靠近经度“环绕”的位置,并且由于地球曲率而不会搜索矩形,则这种方法将不起作用,但没有多少人搜索餐厅评论或在北极或北极有什么太平洋中部。)
You can use (for example) the Google Maps API to geocode a text description of a location (the search term, and the addresses) into a GPS coordinate location. You then check which of the locations in your database is within range of the search term location. The terms and conditions of the use of that API require you to use the geocoding results to display a Google Map though.
Determining "within range" efficiently might be tricky though, you generally want either a GIS-capable database to do the calculations for you. A hackish shortcut that's easy to implement over any DB is taking the points 5 kilometers (or whatever distance you want) north, east, south, and west of the search term location, and then looking for addresses that have latitudes and longitudes between the minimum and maximum latitudes and longitudes that gives you. This page lists what the required formulas are. (This approach will not work if the searched area is near where longitude "wraps around" and doesn't search a rectangle because of the curvature of the earth, but not many people search for restaurant reviews or what have you in the Arctic or the middle of the Pacific.)
您应该查看地理编码。
一种方法是使用 Google Maps API,它允许您将地址转换为坐标,并根据坐标轻松计算出特定距离内的地址。
看看:
http://code.google.com/apis/maps/documentation/webservices /index.html
我确信,如果您寻找“地理编码”,您会发现许多其他解决方案,如果您不喜欢这个特定的解决方案。
You should look at geocoding.
One way to do that is to use the Google Maps API, it allows you to convert an address into coordinates and from those you can easily calculate addresses that are within a certain distance.
Take a look at:
http://code.google.com/apis/maps/documentation/webservices/index.html
I'm sure that if you look for "geocoding" you will find many other solutions, if you don't like this particular one.