Finding nearest city like oodle.com

余生长醉 提交于 2020-01-02 10:05:22

问题


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 detect 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


回答1:


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.



来源:https://stackoverflow.com/questions/4392745/finding-nearest-city-like-oodle-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!