So, I am trying to develop an application that will display user listings. The site should detect user location (I am using maxmind api for that) and then show listsings from user's location + cities within a user-specified radius.
How do I do this? MaxMind API lets me d开发者_如何学运维etect user's city by IP address but how do I find nearby cities?
Reference site: www.oodle.com (you can also manually change city+radius).
Sanguine
Rather than store and compare cities, store and compare latitudes and longitudes, which are concrete locations rather than ambiguous names. All of MaxMind's GeoIP databases provide them. A quick Google search should provide you the math to calculate distances between points on the earth.
If you actually want to find nearby cities, not nearby users as you've said, then you need a database mapping cities to locations. Again, MaxMind provides this with all their databases. Go to their website, go to the page about the database you purchased or downloaded, and look at the instructions for inserting the CSV format into a SQL database. That'll get you the latitude and longitude of each city. Then, again, a Google search will provide you the math to calculate the distance between two points on the earth (lat/long pairs) in a SQL query. Order by that calculation to get the nearest cities.
Sorry to give you only advice rather than code, but there's a lot of little things you've just gotta do yourself to build this site.
精彩评论