[英]Find cities within given mile radius from address
I'm using CakePHP/mysql to build my app and I'm trying to get a list of cities within a given mile radius around an address both supplied by the user. 我正在使用CakePHP / mysql来构建我的应用程序,并且试图获取用户提供的地址周围给定英里半径内的城市列表。 So far I have a list of all US cities in a database with the long/lat.
到目前为止,我在数据库中包含长/短的所有美国城市列表。 I also am using a CakePHP plugin to get the long/lat of all addresses inserted into the database.
我还使用CakePHP插件来获取插入到数据库中的所有地址的长号/尾号。
Now how do I do the last part? 现在我该如何做最后一部分? I'm new to the google maps api but it looks like there is a limit on how many queries I make a day.
我是google maps api的新手,但我每天要查询的次数似乎受到限制。 The only way I can think to do it is to check the distance from the address and compare it to every city in the database and if it is within the given radius then they are selected.
我能想到的唯一方法是检查到地址的距离,并将其与数据库中的每个城市进行比较,如果它在给定的半径内,则将其选中。 It seems like this would be way too database intensive and I would pass my query quotas in one go.
看来这将占用大量数据库资源,并且我将一次性通过查询配额。
Any ideas? 有任何想法吗?
It sounds like you're trying to determine if a given point (city) is within a circle centered on a specific lat/lon. 听起来您正在尝试确定给定点(城市)是否在以特定纬度/经度为中心的圆内。 Here's a similar question .
这是一个类似的问题 。
Run a loop over each city and see if it satisfies the following condition: 在每个城市上运行一个循环,看看它是否满足以下条件:
if ( (x-center_x) 2 + (y-center_y) 2 <= radius 2 )
如果((x-center_x) 2 +(y-center_y) 2 <=半径2 )
If this is too slow, you could turn it into a lookup based on rounding the lat/lon. 如果太慢,则可以基于四舍五入的经/纬度将其转换为查找。 The more values you precompute, the closer to exact you can get.
预计算的值越多,获得的精度就越接近。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.