使用 Google 地图进行邻近搜索
我正在开发一个商店位置应用程序。
查找商店时,它目前会根据地址和邮政编码在谷歌地图中显示位置。
现在我想建立一个功能,还可以显示半径 500 米内的其他商店。 为此,我必须进行邻近搜索/计算。
我最大的问题是我应该如何处理这个问题。
我确实找到此链接,其中包含一些示例代码。但我不确定我是否可以使用该代码(以及我应该使用哪些代码)。有人有更好的例子吗?
另外,我正在考虑向数据库添加一个新表,该表存储每个商店的地理代码。我是否需要比 'id'、'latitude' 和 'longitude' 更多的字段?
更新
我刚刚在 phpro.org 找到此链接 。看来这正是我所需要的!有人使用过他们的例子并可以对此发表评论吗?
I'm developing a store location application.
Looking up a store, it currently shows the location in googlemaps based on address and zip code.
Now I want to build a function which also shows other shops within 500 meter radius.
To do this, I have to do a proximity search / calculation.
My biggest question, is how I should approach this.
I did find this link, which has some example code. But I'm unsure if I can use the code (and which of the codes I should use). Does anyone have better examples?
Also I'm thinking of adding a new table to the database, which stores the geo code for each store. Do I need more fields than 'id', 'latitude' and 'longitude' ?
UPDATE
I just found this link at phpro.org. It looks like it's just what I need! Has anyone used their examples and can comment upon it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法直接使用 google 地图 API 进行半径搜索,但是,您应该知道(或者可以通过对地址进行地理编码来找出)要包含在搜索中的每个兴趣点 (POI) 的纬度和经度。
之后,您可以使用大圆 方程来搜索邻近度,结果证明速度非常快。我们已将其实现为我工作中定位器服务的存储过程,并使用它来搜索超过 3500 个位置,响应时间低于 0.1 秒。
You cant radius search directly with the google maps API, however, you should know (or can figure them out via geocoding their addresses) the latitude and longitude of each point of interest (POI) you want to include in the search.
After this you can use the Great Circle equation to search for proximity, and it turns out to be very fast. We have implemented this as a stored procedure for the locator service at my work and use it to search through >3500 locations with response times under 0.1 seconds.
一些 SQL 实现包含地理空间扩展。在这些实现中,您可以直接编写 WHERE 子句,根据距指定点的距离过滤结果。
检查 SQL 实现的文档。如果它具有地理空间 POINT 类型,则以 POINT 形式输入坐标而不是纬度/经度对是有意义的,如果您要主要按位置访问表,请考虑使用该字段作为空间键。
Some SQL implementations contain geospatial extensions. In those implementations you can directly write a WHERE clause that filters the results by distance from a specified point.
Check the documentation of your SQL implementation. If it has geospatial POINT type, then it makes sense to enter the coordinates as POINTs rather than a lat/lng pair, and consider using that field as a SPATIAL KEY if you're going to be accessing the table mainly by location.