不是我遇到的技术问题,但有人知道如何实施“城市 8 英里内的搜索”
我看起来像Autotrader 网站上的搜索
是否有执行此操作的在线服务(可能是谷歌地图 api?),或者它通常由开发人员构建。
Here are the steps I take to implement this:
Assuming that you are allowing user to search for cities within 8 miles, matching records from Table A, which also has a address or city field.
Step 1: When you are adding a new record to table A, which will be used for searching against later on, via Google Map API you can save the latitude/longitude of that address or city in each row of that table.
Step 2: When user types in the city keyword, again use Google Map API to fetch the latitude longitude of the search keyword city.
Step 3: Armed with the keyword lat/long to match against the table records lat/long, use a query with Harvensine Formula with a "having" statement to fetch the necessary records.
The formula and the mysql query on how to do this, is described well here
The google map API to use is in this google documentation
One thing to note though, is that suppose you enter a city name, say "Los Angeles". It is incorrect to assume that Los Angeles is a "dot" on the map...its a city with a shape. So suppose you say all results within 5 miles of Los Angeles...the question is ambiguous because one might ask - Which end of Los Angeles? For this reason, the google api will return multiple sets of coordinates against the same city, to define the bounding poly line of the location. If your really want your results to be accurate, don't just consider 5 miles from the centre, take the other coords into consideration too, and use union of the results.
如果您要在距离某个位置 X 英里内的 Google 地图上查找位置类型,它可以做到这一点https://developers.google.com/places/documentation/?hl=fr&csw=1#PlaceSearches。
如果您要从某个位置 X 英里内的一组特定位置(如数据库中的位置)中查找位置,则您必须自己完成其中的一些操作。使用谷歌地图获取每个位置的经度和纬度,然后使用这样的公式计算距离,例如http://www.movable-type.co.uk/scripts/latlong.html,然后只显示范围内的结果你想要的距离。