What I\'m trying to achieve I want to enter a US city/state or zip code value. T
ID: 657726 • Letter: W
Question
What I'm trying to achieve I want to enter a US city/state or zip code value. Then enter a radius (ex: 30 - would stand for 30 miles). Then I enter a minimum population (ex: 100000 - would tell the program logic to only look for cities with populations greater than or equal to 100000). The program returns the names of cities within the radius that has populations greater than or equal to the minimum population.
I don't care about super-precise numbers. For example, if a major city barely touches the outside radius, it still counts so I want to include that city's entire population (even though it's only perhaps a small sliver of the actual population) in the output.
My Question Is there software or solutions out there that would allow me to achieve this?
What I'm considering
Google geolocation but don't know if it's possible to do what I'm trying to do
Some Python radius software package I don't know about
Utilizing a giant database lookup table or an API but don't know which route is best from a strategic standpoint?
Explanation / Answer
I would suggest using Google Maps API.
I'm not sure whether you're going to have a database of cities or you would extract that info from someone else's database. Anyhow the logic is as follows:
Get the exact coordinates of the person using Google Maps API (whether on mobile or in the desktop browser);
Get the x + 10km 'square' of cities (x/2 + 5 km in every direction) by specyfying minimum and maximum latitude and longitude around that person. 0.05 degrees in every direction would roughly equal to 5 km:
a. We have the coordinates of the person. The coordinates are A (latitude) and B (longitude)
b. Minimal latitude would be Amin = A - 0.05 Maximum latitude would be Amax = A + 0.05 Minimal longitude would be Bmin = B - 0.05 Maximum longitude would be Bmax = B + 0.05
c. SELECT from your database (or tell your API to select) the cities which are located within the Amin Amax latitudes and Bmin Bmax longitudes
d. If you really need the circle shape: Calculate distance to each city. Here's a nice article for Python -
e. Filter and leave only the cities which are within the necessary distance.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.