简体   繁体   English

从地址查找给定英里半径内的城市

[英]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.

相关问题 返回当前位置x英里半径内的地点列表 - Return list of places within x mile radius of current location 发出谷歌 API http 请求,给定地址,找到关闭的火车站或/和给定半径的公共汽车站? - Make a Google API http request, given an address, find closes train station or/and bus stop given a radius? 在给定半径内显示数据库中的所有位置 - Display all locations from database within a given radius 从给定的英里/公里中找到半径在谷歌地图 - find radius from given miles/kilometer In google Map 查找一个国家/州的所有城市或从 JSON 数据中查找给定城市的州/国家 - Find all cities in a country/state or finding the state/country given a city from JSON data 如何从完整地址数组中获取城市? - How to get cities from an array of full address? 获取给定半径内的纬度和经度,以及以米为单位的给定纬度和经度 - get latitudes and longitudes within given radius and from a given latitude and longitude in meters Google Streetview:在给定半径内显示标记 - Google Streetview: Show markers within given radius 通过谷歌地图 API 是否可以知道从给定点以半径获得的区域内的省份、地区? - Through the Google Maps API it is possible to know the provinces, regions that fall within an area that is obtained with a radius from a given point? 如何在任意点的给定半径内找到所有标记/特征并存储所述标记的纬度/经度? - How do I find all markers/features within a given radius of any arbitrary point and store the lat/lng of said markers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM